I have made two examples that work fine for me with Xalan 2.7.1 Java.
The input XML is as follows:
Code:
<root>
<foo>
<bar>
<baz>a > b</baz>
</bar>
</foo>
</root>
The first XSLT sample uses the CDATA output "hack" with disable-output-escaping:
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="foo">
<xsl:copy>
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:copy-of select="node()"/>
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
With that Xalan outputs
Code:
<?xml version="1.0" encoding="UTF-8"?><root>
<foo><![CDATA[
<bar>
<baz>a > b</baz>
</bar>
]]></foo>
</root>
The second stylesheet imports the one I linked to and uses cdata-section-elements="foo":
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:import href="http://lenzconsulting.com/xml-to-string/xml-to-string.xsl"/>
<xsl:output method="xml" cdata-section-elements="foo"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="foo">
<xsl:copy>
<xsl:call-template name="xml-to-string">
<xsl:with-param name="node-set" select="node()"/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
With that Xalan outputs
Code:
<root>
<foo><![CDATA[
<bar>
<baz>a > b</baz>
</bar>
]]></foo>
</root>
So far as far as I can tell both suggested approaches solve the problem.