[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Multiple replace() in XSLT 2

Subject: Re: Multiple replace() in XSLT 2
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 16 May 2019 19:16:47 -0000
Re:  Multiple replace() in XSLT 2
On 16.05.2019 20:59, Rick Quatro rick@xxxxxxxxxxxxxx wrote:

I have a look up file of find/change pairs that I have to apply to a
text node in my XML document. I am using XSLT 2. Here is an example of
the lookup file:

<?xml version="1.0" encoding="UTF-8"?>

I am reading this in as a global variable, but I am not sure the best
approach for doing multiple replacements on the node. I can use
recursion like in XSLT 1, but I can't think of how to do this in XSLT 2.

I don't understand why you say you know recursion in XSLT 1 but can't do it in XSLT 2.

There could be any number of <findchange> elements in my lookup file.
Any pointers would be appreciated. Thank you very much.

The examples seem to "upper case" the search strings so doing e.g.

  <xsl:variable name="pattern" as="xs:string"

  <xsl:template match="foo/text()">
    <xsl:analyze-string select="." regex="{$pattern}">
           <xsl:value-of select="upper-case(.)"/>
           <xsl:value-of select="."/>

Or declare a key

<xsl:key name="lookup" match="findchange" use="@find"/>


  <xsl:template match="foo/text()">
    <xsl:analyze-string select="." regex="{$pattern}">
           <xsl:value-of select="key('lookup', .,
           <xsl:value-of select="."/>

Not sure if that suffices or if you need to replace one term recursively
in the replacement of a previous term.

And of course depending on the "find" values, to build the regular
expression pattern, you might need to escape metacharacters first, I
think functx has a function for that.

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.