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 Type| Name | 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 Declaration| See XSLT definition. | | XQuery Syntax for July 2004 - January 2007 (1.0): |
|---|
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
} ; | | XQuery Syntax for May 2003: |
|---|
declare namespace functx = "http://www.functx.com"
define function replace-multi
( $arg as xs:string? ,
$changeFrom as xs:string* ,
$changeTo as xs:string* ) as xs:string? {
if (fn:count($changeFrom) > 0)
then functx:replace-multi(
fn:replace($arg, $changeFrom[1],
functx:if-absent($changeTo[1],'')),
$changeFrom[fn:position() > 1],
$changeTo[fn: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 On| functx:if-absent | The first argument if it is not empty, otherwise the second argument |
See AlsoHistory |
|