Description
The functx:replace-multi function performs multiple calls to the fn:replace function. It takes as arguments a sequence of strings or patterns to change from, and sequence of strings to change to. It iterates through the sequences, calling the built-in fn:replace function for each pair in order.
Arguments and Return TypeName | Type | Description |
$arg |
xs:string? |
the string to manipulate |
$changeFrom |
xs:string* |
the sequence of strings or patterns to change from |
$changeTo |
xs:string* |
the sequence of strings to change to |
return value |
xs:string? |
XQuery Function DeclarationSee XSLT definition. | declare namespace functx = "http://www.functx.com";
declare function functx:replace-multi
( $arg as xs:string? ,
$changeFrom as xs:string* ,
$changeTo as xs:string* ) as xs:string? {
if (count($changeFrom) > 0)
then functx:replace-multi(
replace($arg, $changeFrom[1],
functx:if-absent($changeTo[1],'')),
$changeFrom[position() > 1],
$changeTo[position() > 1])
else $arg
} ; |
Exampleslet $fr := | ('[a-c]', 'def', '\d+') | let $to := | ('x', 'y', '0') | return |
XQuery Example | Results |
---|
functx:replace-multi('abcdef123',$fr,$to) |
xxxy0 |
Depends Onfunctx:if-absent | The first argument if it is not empty, otherwise the second argument |
See AlsoHistory |
Recommended Reading:
|