Search code examples
xsltxslt-2.0oxygenxml

XSL - Replace pipe by another character


I use XSLT 2. How I can replace pipe by aonther character ?

For exemple I have an element like this :

<list items="A1|A2|A3"/>

I want to have

<list items="A1,A2,A3"/>

I tried something like this, but not working

<xsl:variable name="result" select="replace(list/@items, '|', ',')"/>

What is problem ?


Solution

  • The replace() function uses regex - and the pipe character is a special character in regex. Either escape the character:

    <xsl:variable name="result" select="replace(list/@items, '\|', ',')"/>
    

    or use the translate() function instead.