XSLT: "use-attribute-sets" attribute is processed when current node is root

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 1.4.0
    • Affects Version/s: 1.4.0, 6
    • Component/s: xml
    • 1.4
    • 1.4
    • generic
    • generic
    • Verified

        According to XSLT 1.0 specification (http://www.w3.org/TR/xslt#copying) "use-attribute-sets" attribute should not be used when current node is a root node, but XSLT processor in JAXP RI 1.4 and JDK 6.0 processes this attribute for a root node. Detailed explanation is given below.

        Consider the following code fragment from file attribset27.xsl (attached):
        "<xsl:template match="/">
        <out>
         <xsl:copy use-attribute-sets="set1">
           <xsl:attribute name="text-decoration">none</xsl:attribute>
         </xsl:copy>
        </out>
        </xsl:template>

        <xsl:attribute-set name="set1">
        <xsl:attribute name="text-decoration">underline</xsl:attribute>
        </xsl:attribute-set>

        <xsl:attribute-set name="set1">
        <xsl:attribute name="color">black</xsl:attribute>
        </xsl:attribute-set>

        <xsl:attribute-set name="set1">
        <xsl:attribute name="font-size">14pt</xsl:attribute>
        </xsl:attribute-set>"

        It produces output presented in file attribset27.out (attached):
        <out font-size="14pt" color="black" text-decoration="none"/>
        So attributes font-size and color appear in the result due to usage of "use-attribute-sets" attribute:
        <xsl:copy use-attribute-sets="set1">
        The correct output should look like:
        <out text-decoration="none"/>

        How to reproduce:
        "java XSLTransform attribset27.xml attribset27.xsl"

        Detailed explanation:
        According to the XSLT 1.0 specification (http://www.w3.org/TR/xslt#copying):
        "The |xsl:copy| element may have a |use-attribute-sets| attribute (see [*7.1.4 Named Attribute Sets*] <http://www.w3.org/TR/xslt#attribute-sets&gt;). This is used only when copying *element nodes*."
        Difference between root nodes vs.element nodes described in XSLT 1.0 data model definition (http://www.w3.org/TR/xslt#data-model). In fact it refers to XPath 1.0 data model.
        XPath 1.0 data model defines root nodes as following (http://www.w3.org/TR/xpath#root-node):
        "The root node is the root of the tree. A root node does not occur except as the root of the tree. The element node for the document element is a child of the root node."
        So "root node" is an XML document as a whole. Element node is just an XML element, a document element cannot be a root node.
        The problem is that in test's template rule is defined as <xsl:template match="/">, so it matches root node, which becomes "context node" for rules defined inside the template, including <xsl:copy> rule.
        Since <xsl:copy> rule is applied to the root node, "use-attribute-sets" should not be used, according to the specification.
        XSLT 1.0 specification Errata (http://www.w3.org/1999/11/REC-xslt-19991116-errata/) does not have any corrections for mentioned parts of the specification.
        According to the XSLT 2.0 specification (http://www.w3.org/TR/xslt20/#copying) "use-attribute-sets" attribute should not be processed for root node too (it is called "document node" there).
        Apache Xalan 2.7.0 also has this bug. Saxon 8.8 does not have it.

              Assignee:
              Santiago Pericasgeertsen
              Reporter:
              Alexey Shurygin (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: