XPATH : replace every ohter whitespace -


i'd replace every other (odd?) space x. result should be:

axb axb axb axb axb

i tried like:

replace ("a b b b b" , " " , "x")[position() mod 2 = 0] 

-- no result.

first of all: fn:replace requires xpath 2.0 (or xquery) compatible query processor.

you cannot use fn:replace predicate this. there no array-like access characters in xpath (like you're used eg. c). solve using fn:tokenize , for-loop, that's getting things rather complicated.

your query did not return result, there 1 result (single element string sequence), predicate returns every second.


use regular expression instead. expression matches on non-space (\s) , space (\s) , replaces patterns version x in between. star quantifier in end important odd number of match groups (like in example).

replace("a b b b b" , "(\s+)\s+(\s+\s*)", "$1x$2") 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -