The <xsl:character-map> command can be used to serialize a single character for any line. However, this problem requires more than one character (an ampersand followed by another character that needs to be replaced).
<xsl:character-map> cannot be used to solve such problems.
Here is a solution to this problem using the XPath 2.0 replace() function:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="text()"> <xsl:value-of select= 'replace( replace( replace(., "&lt;", "<"), "&gt;", ">" ), "&apos;", "'" ) '/> </xsl:template> </xsl:stylesheet>
when this conversion is applied to the following XML document :
<xml_element>Distrib = SU & &apos;Prem &lt;&gt; 0</xml_element>
the desired result is obtained :
<xml_element>Distrib = SU & 'Prem <> 0</xml_element>
source share