Menu

value-of statement

Help
2001-12-17
2012-10-08
  • Jim Parsons

    Jim Parsons - 2001-12-17

    I am posting this issue to this list rather than the general XSL-List, because it is a Saxon specific issue.

    Saxon complains that in the stylesheet below, the 'disable-output-escaping="yes"' clause in the value-of line is an xsl parse error, as disable-output-escaping is being applied to a non-text node. Xalan does not care about this...

    Here is the problematic section from one of my xsl files:

    =======================================================
    <xsl:output method="html" indent="yes"/>

    <xsl:template match="bebop:link"
            xmlns:bebop="http://www.arsdigita.com/bebop/1.0">
        <a>
            <xsl:for-each select="@*">
                <xsl:attribute name="{name()}">
            <xsl:value-of disable-output-escaping="yes" select="."/>
                </xsl:attribute>
        </xsl:for-each>
        <xsl:apply-templates />
        </a>
    </xsl:template>
    ===================================================

    This is a typical bit of xml that is processed by the above file:

    <?xml version="1.0" encoding="utf-8"?>
    <bebop:page xmlns:bebop="http://www.arsdigita.com/bebop/1.0">
       <bebop:title>Link Example</bebop:title>
       <bebop:boxPanel axis="2" center="false" width="100%">
          <bebop:cell>
             <bebop:link href="moffet/?g11n.enc=ISO-8859-1" type="link">
                <bebop:label>Link Text</bebop:label>
             </bebop:link>
          </bebop:cell>
       </bebop:boxPanel>

    1) Is this because Saxon follows the spec closer? 2) Can anyone suggest an approach to rewriting this template so that I don't suffer from this error with Saxon? I believe that I need to disable-output-escaping as one of the attribute values I need printed out is the href target for the link...

    Thank You,

    Jim Parsons
    Ars Digita Corp.
    </bebop:page>

     
    • Michael Kay

      Michael Kay - 2001-12-17

      The XSLT spec is quite explicit (section 16.4) that it's an error to use disable-output-escaping on an xsl:value-of instruction used to generate the string value of an attribute node.

      Saxon has an extension saxon:disable-output-escaping="yes" which you can use on xsl:attribute itself.

      But actually you probably don't need it here. URI's in the href attribute of an <a> element should be escaped as the XSLT standard specifies, and Saxon will generate correct HTML that works with every browser except some really ancient ones.

      Mike Kay