tags:

views:

88

answers:

2

How to use

      fn:replace(string,pattern,replace) 

in XSLT

is it like < fn:replace(...)/>??

A: 

I think you do it this way:

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

Edit:

Found this question on stackoverflow

naikus
+2  A: 

The function is specified 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 some special substitution syntax.

Here are some examples:

# simple replacement
replace('query', 'r', 'as')               queasy

# character class
replace('query', '[ry]', 'l')             quell

# capturing group substitution
replace('abc123', '([a-z])', '$1x')       axbxcx123

# practical example
replace('2315551212',                     (231) 555-1212
    '(\d{3})(\d{3})(\d{4})',
    '($1) $2-$3'
)

References

polygenelubricants
@ polygenelubricants : Thank you :-) how to use this in an xsl file
Pramodh
@polygenelubricants: Very good answer (+1). BTW, what a name :)
Dimitre Novatchev