CDATA and ?>

Help
Olaf Rauch
2002-08-28
2014-01-27
  • Olaf Rauch

    Olaf Rauch - 2002-08-28

    Hi,

    we found the following problem (with Saxon 6.5.2 and 7.2) where we need help. It may be a bug in Saxon, since it works in MSXSL 4.

    We want to generate PHP calls in attributes (for HTML forms).
    The PHP code is encapsualted in <% and %>.
    During generation with SAXON the last ">" will be converted to an html entitiy instead of "copied" to the output.

    This is a sample XSL:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.1"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:saxon="http://icl.com/saxon"
        extension-element-prefixes="saxon">
       
        <xsl:output method="html" version="1.0" encoding="iso-8859-1" indent="yes"/>
        <xsl:template match="*|/">
            <form>
                <xsl:attribute name="action">
                    <xsl:text disable-output-escaping="yes"><![CDATA[<? echo $TEST; ?>]]></xsl:text>
                </xsl:attribute>
            </form>
        </xsl:template>
    </xsl:stylesheet>

    This stylesheet produces the following wrong output:
    <form action="<? echo $TEST; ?&gt;"></form>

    Correct (produced by MSXSL4) would be:
    <form action="<? echo $TEST; ?>"></form>

    Any ideas?

    Many thanks for your help!

    Best
    Olaf

     
    • Michael Kay

      Michael Kay - 2002-08-28

      Saxon is correct and MSXML4 is wrong.

      The XSLT 1.0 spec is explicit: Section 16.4 says "it is an error to disable output escaping for an xsl:text element that is used to generate the string-value of an attribute node... the XSLT processor may signal the error or may recover by ignoring the disable-output-escaping attribute."

      Saxon has an extension, <xsl:attribute saxon:disable-output-escaping="yes">, that allows you to achieve what you want. In the latest XSLT 2.0 draft (and in Saxon 7.2) this has been incorporated into the standard.

      Michael Kay

       
      • Olaf Rauch

        Olaf Rauch - 2002-08-29

        Hi Michael,

        ok I understand. It works now. Many thanks for your help!

        btw: why was the first "<" character not converted to an entity?

        Best
        Olaf

         
    • Michael Kay

      Michael Kay - 2002-08-29

      The XSLT 1.0 spec explicitly says that the html output method should not escape "<" characters occurring in attribute values. I've not idea why, I just do what I'm told.

      Michael Kay

       
      • Olaf Rauch

        Olaf Rauch - 2002-08-29

        Long live the spec.... :)
        /Olaf

         
  • senthur selvi

    senthur selvi - 2014-01-27

    Hi

    I am using saxon engine. Using xquery i need to add dynamically formed xml into cdata section as per provider. I am not using xslt. Please help me in xquery.

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks