[xslt] xsl:copy use-attribute-set



Hi

Please can you apply the attached patch to fix the following problem with
<xsl:copy use-attribute-sets="...">

If you copy an element using two attribute sets which contain attributes
with the same name, the second occurence of the attribute should overwrite
the first. However, libxslt kept the first value of the attribute, ignoring
any subsequent definitions from attribute sets.

i.e.
...
<xsl:copy use-attribute-sets="A B">
</xsl:copy>
...
<xsl:attribute-set name="A">
  <xsl:attribute name='align'>center</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="B">
  <xsl:attribute name='align'>right</xsl:attribute>
</xsl:attribute-set>
...
In the output you should get align="right", but libxslt returns
align="center"

In xsltAttributeInternal(), the block of code that adds the attribute
explicilty checks to see if the attribute is from an attribute set and only
adds it if it hasn't already been added to the element. My patch removes
this if statement.

I've checked back in CVS and found bug 59757, the fix for which included
this test. It appears that the test case given with this bug still works
correctly, so I don't think the change will have any other nasty side
effects. To make sure, I've included below my own test case that covers both
the bug 59757 and my problem.

Thanks,
Richard

Stylesheet 107.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 select="/XML_DATA/*"/>
 </xsl:template>

 <xsl:template match="@*|node()">
  <xsl:copy use-attribute-sets='H1 P Q'>
   <xsl:attribute name='align'>howdy</xsl:attribute>
  </xsl:copy>
 </xsl:template>

 <xsl:attribute-set name="H1">
  <xsl:attribute name='align'>center</xsl:attribute>
  <xsl:attribute name='style'>color:red</xsl:attribute>
 </xsl:attribute-set>

 <xsl:attribute-set name="P">
  <xsl:attribute name='align'>left</xsl:attribute>
  <xsl:attribute name='style'>color:blue</xsl:attribute>
  <xsl:attribute name='fish'>color:gold</xsl:attribute>
 </xsl:attribute-set>

 <xsl:attribute-set name="Q">
  <xsl:attribute name='align'>middle</xsl:attribute>
  <xsl:attribute name='style'>color:yellow</xsl:attribute>
  <xsl:attribute name='fish'>color:tuna</xsl:attribute>
  <xsl:attribute name='size'>large</xsl:attribute>
 </xsl:attribute-set>

</xsl:stylesheet>

XML 107.xsl
<?xml version="1.0"?>
<H1 align="howdy" style="color:yellow" fish="color:tuna" size="large"/><P
align="howdy" style="color:yellow" fish="color:tuna" size="large"/>

Original Output
<?xml version="1.0"?>
<H1 align="howdy" style="color:red" fish="color:gold" size="large"/><P
align="howdy" style="color:red" fish="color:gold" size="large"/>

Fixed Output
<?xml version="1.0"?>
<H1 align="howdy" style="color:yellow" fish="color:tuna" size="large"/><P
align="howdy" style="color:yellow" fish="color:tuna" size="large"/>

attribute_set.diff



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]