disable-output-escaping="yes" and xsl:result-document

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

disable-output-escaping="yes" and xsl:result-document

Stefan Krause

Hello,

 

I have a problem using disable-output-escaping="yes" in connection with xsl:result-document. The following stylesheet works fine:

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="3.0"
    >

    <xsl:output method="xml"/>

    <xsl:template match="/">
        <xsl:variable name="trash" as="document-node()">
            <xsl:document>
                <root>
                    <element>text<xsl:text disable-output-escaping="yes"><![CDATA[</element><element>]]></xsl:text>text</element>
                </root>
            </xsl:document>
        </xsl:variable>
        <xsl:sequence select="$trash"/>
        <!--<xsl:result-document href="trash_01.xml" method="xml">
            <xsl:sequence select="$trash"/>
        </xsl:result-document>-->
    </xsl:template>

</xsl:stylesheet>

 

The expected result is:

 

<?xml version="1.0" encoding="UTF-8"?><root><element>text</element><element>text</element></root>

 

If I remove the comment from the xsl:result-document block, the output (both in the primary output file and in trash_01.xml) is:

 

<?xml version="1.0" encoding="UTF-8"?><root><element>text&lt;/element&gt;&lt;element&gt;text</element></root>

 

Its look like a kind of interference of xsl:result-document with the serialization parameters.

 

Do I something wrong (beside the awkward coding)? Is there a way to avoid this behavior?

 

Thank you,

 

Stefan


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: disable-output-escaping="yes" and xsl:result-document

Michael Kay
Sorry for the delay in responding. 99% of the moderation requests for the saxon-help list are for SPAM, so I don't attend to it very often. In future, please use the forums at saxonica.plan.io.

It's not xsl:result-document that's the issue, it's xsl:variable. disable-output-escaping only has effect when you are writing directly to a serializer. The content of a variable is an in-memory tree, so no escaping takes place when writing to a variable, therefore disabling escaping has no effect.

Michael Kay
Saxonica


On 3 Jul 2017, at 12:13, Stefan Krause <[hidden email]> wrote:

Hello,

 

I have a problem using disable-output-escaping="yes" in connection with xsl:result-document. The following stylesheet works fine:

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="3.0"
    >

    <xsl:output method="xml"/>

    <xsl:template match="/">
        <xsl:variable name="trash" as="document-node()">
            <xsl:document>
                <root>
                    <element>text<xsl:text disable-output-escaping="yes"><![CDATA[</element><element>]]></xsl:text>text</element>
                </root>
            </xsl:document>
        </xsl:variable>
        <xsl:sequence select="$trash"/>
        <!--<xsl:result-document href="trash_01.xml" method="xml">
            <xsl:sequence select="$trash"/>
        </xsl:result-document>-->
    </xsl:template>

</xsl:stylesheet>

 

The expected result is:

 

<?xml version="1.0" encoding="UTF-8"?><root><element>text</element><element>text</element></root>

 

If I remove the comment from the xsl:result-document block, the output (both in the primary output file and in trash_01.xml) is:

 

<?xml version="1.0" encoding="UTF-8"?><root><element>text&lt;/element&gt;&lt;element&gt;text</element></root>

 

Its look like a kind of interference of xsl:result-document with the serialization parameters.

 

Do I something wrong (beside the awkward coding)? Is there a way to avoid this behavior?

 

Thank you,

 

Stefan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: disable-output-escaping="yes" and xsl:result-document

Michael Kay
Actually it's a bit more subtle than this. With the stylesheet as written (xsl:result-document commented out), the only reason it works is that the variable $trash is only used once, and is therefore inlined; this means that the code is executed as if you had written

<xsl:template match="/">
   <xsl:document>
                <root>
                    <element>text<xsl:text disable-output-escaping="yes"><![CDATA[</element><element>]]></xsl:text>text</element>
                </root>
   </xsl:document>
</xsl:template>

which means the xsl:text instruction is writing directly to the serialized, so d-o-e works.

There's actually quite a history to this issue, referred to within the WG as "sticky d-o-e". Erratum E2 to XSLT 1.0 specified that d-o-e should be sticky (see https://www.w3.org/1999/11/REC-xslt-19991116-errata/) - that is, your code should work the way you expect. 

XSLT 2.0 §4.7 says that the disable-escaping bit can only be set when writing to a final result tree (i.e. not to a variable), and §20.2 restates this in the form "If output escaping is disabled for an xsl:value-of or xsl:text instruction evaluated when temporary output state is in effect, the request to disable output escaping is ignored."

Error XTRE1630, a little inconsistently, says that this is a recoverable dynamic error, and the recovery action is to ignore the d-o-e request (in other words the processor has the option of raising an error or ignoring the request).

Appendix J.1.4 of XSLT 2.0 says "An erratum to XSLT 1.0 specified what has become known as "sticky disable-output-escaping": specifically, that it should be possible to use disable-output-escaping when writing a node to a temporary tree, and that this information would be retained for use when the same node was later copied to a final result tree and serialized. XSLT 2.0 no longer specifies this behavior (though it permits it, at the discretion of the implementation). "

but erratum XT.E32 (in https://www.w3.org/XML/2007/qt-errata/xslt-errata.html) corrects this by deleting the final parenthetical phrase.

XSLT 3.0 continues the saga: see https://www.w3.org/Bugs/Public/show_bug.cgi?id=30109 for the gory detail.

Michael Kay
Saxonica


On 23 Jul 2017, at 10:47, Michael Kay <[hidden email]> wrote:

Sorry for the delay in responding. 99% of the moderation requests for the saxon-help list are for SPAM, so I don't attend to it very often. In future, please use the forums at saxonica.plan.io.

It's not xsl:result-document that's the issue, it's xsl:variable. disable-output-escaping only has effect when you are writing directly to a serializer. The content of a variable is an in-memory tree, so no escaping takes place when writing to a variable, therefore disabling escaping has no effect.

Michael Kay
Saxonica


On 3 Jul 2017, at 12:13, Stefan Krause <[hidden email]> wrote:

Hello,

 

I have a problem using disable-output-escaping="yes" in connection with xsl:result-document. The following stylesheet works fine:

 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="3.0"
    >

    <xsl:output method="xml"/>

    <xsl:template match="/">
        <xsl:variable name="trash" as="document-node()">
            <xsl:document>
                <root>
                    <element>text<xsl:text disable-output-escaping="yes"><![CDATA[</element><element>]]></xsl:text>text</element>
                </root>
            </xsl:document>
        </xsl:variable>
        <xsl:sequence select="$trash"/>
        <!--<xsl:result-document href="trash_01.xml" method="xml">
            <xsl:sequence select="$trash"/>
        </xsl:result-document>-->
    </xsl:template>

</xsl:stylesheet>

 

The expected result is:

 

<?xml version="1.0" encoding="UTF-8"?><root><element>text</element><element>text</element></root>

 

If I remove the comment from the xsl:result-document block, the output (both in the primary output file and in trash_01.xml) is:

 

<?xml version="1.0" encoding="UTF-8"?><root><element>text&lt;/element&gt;&lt;element&gt;text</element></root>

 

Its look like a kind of interference of xsl:result-document with the serialization parameters.

 

Do I something wrong (beside the awkward coding)? Is there a way to avoid this behavior?

 

Thank you,

 

Stefan

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Loading...