xmlxsltxslt-2.0saxon

How to correctly disable output escaping with XSL and Saxon?


I am using Saxon-He to process this code (I used this post to get the idea):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    <xsl:key name="elelsById" match="elel" use="@elelEntity" />

    <xsl:template match="/">
        <xsl:text disable-output-escaping="yes">&#xA;&lt;!DOCTYPE dmodule [&#xA;</xsl:text>
        <xsl:text disable-output-escaping="yes">&lt;!NOTATION cgm PUBLIC "-//USA-DOD//NOTATION Computer Graphics Metafile//EN"&gt;&#xA;</xsl:text>

        <xsl:for-each select="//elel[generate-id() = generate-id(key('elelsById', @elelEntity)[1])]">
            <xsl:text disable-output-escaping="yes">&lt;!ENTITY </xsl:text>
            <xsl:value-of select="@elelEntity" />
            <xsl:text> SYSTEM "</xsl:text>
            <xsl:value-of select="@elelEntity" />
            <xsl:text disable-output-escaping="yes">.cgm" NDATA cgm &gt;&#xA;</xsl:text>
        </xsl:for-each>

        <xsl:text disable-output-escaping="yes">]&gt;&#xA;</xsl:text>
        <xsl:apply-templates/>
    </xsl:template>

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

My output looks like this:

<?xml version="1.0" encoding="UTF-8"?>
&lt;!DOCTYPE dmodule [
&lt;!NOTATION cgm PUBLIC "-//USA-DOD//NOTATION Computer Graphics Metafile//EN"&gt;
&lt;!ENTITY ELEL-A-01 SYSTEM "ELEL-A-01.cgm" NDATA cgm &gt;
&lt;!ENTITY ELEL-A-05 SYSTEM "ELEL-A-05.cgm" NDATA cgm &gt;
]&gt;
<!-- xml content -->

I was expecting that the &lt; and &gt; would be replaced to < and >

I removed disable-output-escaping="yes" and the result is the same.

I saw that Saxon contains this extension saxon:doctype, but it is available only for Saxon-PE or Saxon-EE.

What am I missing in my implementation?


Solution

  • Your code as is should work if you let Saxon serialize the result so that it can take the DOE into account; if that doesn't work it usually means you are using a transformation destination like a DOM or XDM tree instead of a file or stream.

    You can see part of your code working this online fiddle with Saxon HE. Result there is e.g.

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE dmodule [
    <!NOTATION cgm PUBLIC "-//USA-DOD//NOTATION Computer Graphics Metafile//EN">
    ]>
    <dmodule>...</dmodule>