[xsl] disable-output-encoding with xsl:copy

Subject: [xsl] disable-output-encoding with xsl:copy
From: Robert Capasso <rcapasso@xxxxxxxxxxxxx>
Date: Mon, 30 Apr 2007 18:30:23 -0400
Hi all-

I am using Saxon 6.5.5 with XSLT version 1.1.

I'm currently working on a transformation which utilizes the identity
template to perform a deep copy of all nodes in a set with the
exception of one certain type of node ('graphic') and any of its
descendants.  These nodes are handled separately in their own
template.  The input and output is XML, with some HTML character
codes contained within the text of the nodes being copied.

The structural bit copies just fine, with content and attributes
showing up on the other side as well.  The only issue I'm having is
with certain HTML character codes (e.g. '&#8220;').  These seem to be
getting encoded(decoded?) during the transformation.  I want to
preserve the character codes without specifying the xsl:output method
as "html".

Below is the relevant template along with the input and output for a
sample node:

<xsl:template mode="copy" match="@*|node()">
    <xsl:if test="not(ancestor::graphic)">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
    </xsl:if>
</xsl:template>

input: <p>&#8220;You can&#8217;t always get what you
want&#8230;&#8221;</p>

output: <p>You cant always get what you want</p>

I would like the text content of the output to exactly match the
content of the input.

I have tried this alternate method but run into the same problem with
the added effect of generating a ton of 'invalid element name' errors:
<xsl:template mode="copy" match="node()">
    <xsl:if test="not(ancestor::graphic)">
        <xsl:element name="name(.)" namespace="namespace-uri(.)">
            <xsl:copy-of select="@*"/>
            <xsl:value-of select="text()" disable-output-
escaping="yes"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:element>
    </xsl:if>
</xsl:template>

Any help would be appreciated!
-Robert

Current Thread