home contribute faq download

FunctX XQuery Functions

functx:replace-multi

Performs multiple replacements, using pairs of replace parameters

Google
Webdatypic.com

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

NameTypeDescription
$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.
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
 } ;

Examples

let $fr :=
('[a-c]', 'def', '\d+')
let $to :=
('x', 'y', '0')
return
XQuery ExampleResults
functx:replace-multi('abcdef123',$fr,$to)
xxxy0

Depends On

functx:if-absentThe first argument if it is not empty, otherwise the second argument

See Also

fn:replaceReplaces parts of a string that match a regular expression
functx:replace-firstReplaces the first match of a pattern
functx:replace-beginningReplaces the beginning of a string, up to a matched pattern

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, https://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery