2

I want to replace a single / with the word, and. This is what I have now:

Code:

<xsl:output omit-xml-declaration="yes" indent="yes"/>

!-- identity transform -->

<xsl:template match="node()|@*">

    <xsl:copy>
        xsl:apply-templates select="node()|@*"/>
    </xsl:copy>

</xsl:template>

!-- exception -->
<xsl:template match="*[local-name()='Category']/@CleanName">
    <xsl:attribute name="CleanName">
           <xsl:value-of select="translate('Cd /dvd inlays', '/ ', 'and')" />
    </xsl:attribute>
</xsl:template>

Input:

<Category ID="129" CleanName="Cd /dvd inlays"></Category>

Output:

"Cdnadvdninlays"

Giving:

"Cd /dvd inlays"

Needed:

"cd and dvd inlays"
kjhughes
  • 106,133
  • 27
  • 181
  • 240

1 Answers1

2

translate() replaces single characters with single characters, not single characters with strings. In your case, you're replacing / with a and SPACE with n – not what you want.

You want replace() instead. Unfortunately, replace() requires XSLT 2.0. For replace functionality in XSLT 1.0, see XSLT string replace.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • can you give me an example what it should be? – jeroen poortman Apr 30 '18 at 12:13
  • No, I've given you everything you need. If you want further help, ***after having actually tried to apply this***, then follow-up with a request for a *specific* clarification. Thanks. – kjhughes Apr 30 '18 at 12:36