xsl:use-attribute-sets in libxslt not conforming to the XSLT spec

Alexey Neyman <[email protected]> Mon, 11 Feb 2019 16:34:08 -0800
Newsgroups gmane.comp.gnome.lib.xslt
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------53FB0C35721518306BF70BD4
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit

Hi,

I noticed since version 1.1.30 of libxslt, the attributes on the literal 
element are not merged correctly with the attributes specified on the 
element itself. The language in the spec [1] ("7.1.4 Named Attribute 
Sets") is as follows:

 > Thus, for a literal result element, attributes from attribute sets 
named in an xsl:use-attribute-sets attribute will be added first, in the 
order listed in the attribute; next, attributes specified on the literal 
result element will be added; finally, any attributes specified by 
xsl:attribute elements will be added. Since adding an attribute to an 
element replaces any existing attribute of that element with the same 
name, this means that attributes specified in attribute sets can be 
overridden by attributes specified on the literal result element itself.

Below is a small test case that has two attribute sets ("as1", "as2"; 
used in that order) + attributes specified on the element itself 
("element") and attributes specified via <xsl:attribute/> in the content 
of the literal element. Per spec, the output of the test case should be:

<bar a1="attr" a2="element" a3="as2" a4="as1"/>

With 1.1.30 and newer, the output is:

<bar a1="attr" a2="as2" a3="as2" a4="as1"/>

Before 1.1.30, the output was:

<bar a1="attr" a2="element" a3="as1" a4="as1"/>

The commit [2] that changed this behavior apparently fixed the order of 
attributes merged from multiple attribute sets (see a3/a4 attributes 
above) but in doing so, broke the handling of the attributes from the 
literal element (see a2 attribute above).

This, for example, breaks the docbook stylesheet customizations for the 
titlepage (which auto-generate an XSLT stylesheet using both an 
attribute sets and attributes on a literal element).

The test case:

---- a.xsl ----
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">
   <xsl:template match="*">
     <xsl:apply-templates/>
   </xsl:template>

   <xsl:attribute-set name="as1">
     <xsl:attribute name="a1">as1</xsl:attribute>
     <xsl:attribute name="a2">as1</xsl:attribute>
     <xsl:attribute name="a3">as1</xsl:attribute>
     <xsl:attribute name="a4">as1</xsl:attribute>
   </xsl:attribute-set>

   <xsl:attribute-set name="as2">
     <xsl:attribute name="a1">as2</xsl:attribute>
     <xsl:attribute name="a2">as2</xsl:attribute>
     <xsl:attribute name="a3">as2</xsl:attribute>
   </xsl:attribute-set>

   <xsl:template match="foo">
     <bar xsl:use-attribute-sets="as1 as2" a1="element" a2="element">
       <xsl:attribute name="a1">attr</xsl:attribute>
     </bar>
   </xsl:template>
</xsl:stylesheet>

---- a.xml ----
<?xml version="1.0"?>
<foo/>

[1] https://www.w3.org/TR/1999/REC-xslt-19991116
[2] 
https://gitlab.gnome.org/GNOME/libxslt/commit/05f70130433478c1075ce8b6fdc4c4dadf51d33e

Regards,
Alexey.


--------------53FB0C35721518306BF70BD4
Content-Type: text/xml;
 name="a.xml"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="a.xml"

<?xml version="1.0"?>
<foo/>

--------------53FB0C35721518306BF70BD4
Content-Type: application/xslt+xml;
 name="a.xsl"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="a.xsl"

PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjx4c2w6c3R5bGVzaGVldCB4bWxuczp4c2w9Imh0dHA6
Ly93d3cudzMub3JnLzE5OTkvWFNML1RyYW5zZm9ybSIgdmVyc2lvbj0iMS4wIj4KICA8eHNs
OnRlbXBsYXRlIG1hdGNoPSIqIj4KICAgIDx4c2w6YXBwbHktdGVtcGxhdGVzLz4KICA8L3hz
bDp0ZW1wbGF0ZT4KCiAgPHhzbDphdHRyaWJ1dGUtc2V0IG5hbWU9ImFzMSI+CiAgICA8eHNs
OmF0dHJpYnV0ZSBuYW1lPSJhMSI+YXMxPC94c2w6YXR0cmlidXRlPgogICAgPHhzbDphdHRy
aWJ1dGUgbmFtZT0iYTIiPmFzMTwveHNsOmF0dHJpYnV0ZT4KICAgIDx4c2w6YXR0cmlidXRl
IG5hbWU9ImEzIj5hczE8L3hzbDphdHRyaWJ1dGU+CiAgICA8eHNsOmF0dHJpYnV0ZSBuYW1l
PSJhNCI+YXMxPC94c2w6YXR0cmlidXRlPgogIDwveHNsOmF0dHJpYnV0ZS1zZXQ+CgogIDx4
c2w6YXR0cmlidXRlLXNldCBuYW1lPSJhczIiPgogICAgPHhzbDphdHRyaWJ1dGUgbmFtZT0i
YTEiPmFzMjwveHNsOmF0dHJpYnV0ZT4KICAgIDx4c2w6YXR0cmlidXRlIG5hbWU9ImEyIj5h
czI8L3hzbDphdHRyaWJ1dGU+CiAgICA8eHNsOmF0dHJpYnV0ZSBuYW1lPSJhMyI+YXMyPC94
c2w6YXR0cmlidXRlPgogIDwveHNsOmF0dHJpYnV0ZS1zZXQ+CgogIDx4c2w6dGVtcGxhdGUg
bWF0Y2g9ImZvbyI+CiAgICA8YmFyIHhzbDp1c2UtYXR0cmlidXRlLXNldHM9ImFzMSBhczIi
IGExPSJlbGVtZW50IiBhMj0iZWxlbWVudCI+CiAgICAgIDx4c2w6YXR0cmlidXRlIG5hbWU9
ImExIj5hdHRyPC94c2w6YXR0cmlidXRlPgogICAgPC9iYXI+CiAgPC94c2w6dGVtcGxhdGU+
CjwveHNsOnN0eWxlc2hlZXQ+Cg==
--------------53FB0C35721518306BF70BD4
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
xslt mailing list, project page http://xmlsoft.org/XSLT/
[email protected]
https://mail.gnome.org/mailman/listinfo/xslt

--------------53FB0C35721518306BF70BD4--