How to use fn: replace (string, pattern, replace) in XSLT

How to use

fn:replace(string,pattern,replace) 

in XSLT

- this is like <n: replace (...) / "> ??

+6
xml xslt
source share
2 answers

The function is defined as follows:

 fn:replace($input, $pattern, $replacement, [$flags]) $input xs:string? the string to change $pattern xs:string regular expression to match the areas to be replaced $replacement xs:string the replacement string $flags xs:string flags for multiline mode, case insensitivity, etc return value xs:string 

Note that $pattern is a regular expression , and the replacement string also has special wildcard syntax.

Here are some examples:

 # simple replacement replace('query', 'r', 'as') queasy # character class replace('query', '[ry]', 'l') quell # capturing group substitution replace('abc123', '([az])', '$1x') axbxcx123 # practical example replace('2315551212', (231) 555-1212 '(\d{3})(\d{3})(\d{4})', '($1) $2-$3' ) 

References

+14
source share

I think you do it like this:

 <xsl:value-of select="fn:replace(value, 'some-pattern', 'with some text')" /> 

Edit:

Found this fooobar.com/questions/736701 / ...

+5
source share

All Articles