The replace() function
Smartsite 7.4 - ...
The replace() XPath 2.0 function returns a string from the input string by replacing any substrings that match a given regular expression pattern with a supplied replacement string.
| XML |
|
|---|---|
string fn:replace(input, string pattern, string replacement) |
|
Parameters:
- input: a node reference or string literal.
- string pattern: the pattern to match (regular expression).
- string replacement: the replacement string.
Example
| XML |
|
|---|---|
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:exf="http://smartsite.nl/namespaces/xforms/1.0"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
<head>
<title>Example</title>
<xf:model>
<xf:instance>
<data xmlns="">
<tekst>www.formulierenserver.nl</tekst>
</data>
</xf:instance>
</xf:model>
</head>
<body>
<xf:group>
<xf:output value="fn:replace('abracadabra', 'bra', '*')" />
<xf:output value="fn:replace('abracadabra', 'a.*a', '*')" />
<xf:output value="fn:replace('abracadabra', 'a.*?a', '*')" />
<xf:output value="fn:replace('abracadabra', 'a', '')" />
<xf:output value="fn:replace('abracadabra', 'a(.)', 'a$1$1')" />
<xf:output value="fn:replace(tekst, 'www\.', '')" />
</xf:group>
</body>
</html>
|
|
The result will be:
a*cada*
*
*c*bra
brcdbr
abbraccaddabbra
formulierenserver.nl
*
*c*bra
brcdbr
abbraccaddabbra
formulierenserver.nl
Namespace
This function is available within the XPath 2.0 namespace (http://www.w3.org/2005/xpath-functions).