home contribute faq download

FunctX XSLT Functions

functx:replace-multi

Performs multiple replacements, using pairs of replace parameters

Google
Webxsltfunctions.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?

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:replace-multi" as="xs:string?"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="arg" as="xs:string?"/>
  <xsl:param name="changeFrom" as="xs:string*"/>
  <xsl:param name="changeTo" as="xs:string*"/>

  <xsl:sequence select="
   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
 "/>

</xsl:function>

Examples

<xsl:variable name="fr" select="('[a-c]', 'def', '\d+')"/>
<xsl:variable name="to" select="('x', 'y', '0')"/>
XPath 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, http://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery