You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by zo...@ca.ibm.com on 2002/07/08 21:36:19 UTC

[PATCH] Bug 4603 (long)

Hello,

     I've just submitted a patch for Bugzilla bug 4603 
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4603>.  Thanks to Ilene 
Seeleman and Morris Kwan who helped by reviewing the patch.

     Following is a detailed explanation of the problem and the proposed 
patch.  My apologies for the length of this note, but it took me some time 
to understand the required behaviour and the source of the problem, so I 
thought this information might benefit anyone interested.

     The problem has to do with the way xsl:attribute-set elements are 
merged.  According to the rules in Section 7.1.4 of XSLT 1.0 [1], it is an 
error for two attribute-set elements to have the same name, but if a 
processor doesn't report the error (as Xalan and XSLTC do not), it should 
merge their sets of xsl:attribute elements, with any duplicates being 
resolved in favour of those appearing later in the stylesheet.

     According to 7.1.4 plus the published errata, for a stylesheet 
fragment like the following, any xsl:attribute elements in an 
xsl:attribute-set take precedence over any brought in via a 
use-attribute-sets attribute; in addition, the attributes brought in via 
use-attribute-sets are treated as if they appeared locally in the 
definition of the attribute-set if it's sbusequently merged with any other 
attribute-set with the same name.

<xsl:attribute-set name="abc" use-attribute-sets="s1 s2">
  ...
</xsl:attribute-set>
<xsl:attribute-set name="abc" use-attribute-sets="s3">
  ...
</xsl:attribute-set>
<xsl:attribute-set name="s1">
  ...
</xsl:attribute-set>
<xsl:attribute-set name="s3" use-attribute-sets="s4">
  ...
</xsl:attribute-set>
<xsl:attribute-set name="s3">
  ...
</xsl:attribute-set>
<xsl:attribute-set name="s4">
  ...
</xsl:attribute-set>
<xsl:attribute-set name="s2">
  ...
</xsl:attribute-set>

So in the preceding fragment, attribute-set abc is treated as if it 
contained xsl:attribute elements that appeared in the following order, 
with those appearing later taking precedence.

1. Those copied from s1 followed by those copied from s2
2. Those that appeared in the content of the first version of abc
3. Those copied from s3, which is determined as follows:
  3.1 Those copied from s4
  3.2 Those that appeared in the content of the first version of s3
  3.3 Those that appeared in the content of the second version of s3
4. Those that appeared in the content of the second version of abc

     AttributeSet wasn't merging the attribute-set elements in that way. 
Instead it merged the lists of attribute-sets named in use-attribute-set 
attributes for the two elements and merged the xsl:attribute elements that 
appeared in the content of the two elements being merged, which means that 
steps two and three in the list above (the outer list) were reversed.  On 
top of it, when the merging of the content of the two attribute-set 
elements happened, the elements from the first were copied in reverse 
order.  The old pre-merge AttributeSet was then marked as being ignored.

     When AttributeSet generated code for an attribute-set, it created a 
single method for the ultimate merged attribute-set (ignoring the other 
earlier copies).  That single method called methods for each set listed in 
its use-attribute-sets and then added attributes that were listed locally. 
 So the method for abc called methods for s1, s2 and s3, and then added 
attributes that appeared in the contents of the two versions of abc.

     Under my proposed patch, when an attribute-set with the same name as 
an earlier one is encountered, the new AttributeSet object simply points 
to the previous one, rather than merging in information from the previous 
one.  Each such attribute-set element has a method generated for it, and 
the first thing the method does is call the method associated with the 
previous version, if any, then calls the methods for attribute-sets 
specified in use-attribute-sets and then adds the attributes specified 
locally in the content of the attribute-set element.  That should cause 
the attributes to be processed in the correct order described above.

     Alternatively, I could have continued to merge information into a 
single AttributeSet object, but I would have had to somehow mark the list 
of values from the use-attribute-set attributes and the merged list of 
attributes from the attribute-set content to indicate the order in which 
they should be processed.  That would result in slightly more efficient 
code in the translet, but I didn't actually see any performance tests that 
test this merging situation.

Thanks,

Henry
[1] http://www.w3.org/TR/xslt#attribute-sets
------------------------------------------------------------------
Henry Zongaro      Xalan development
IBM SWS Toronto Lab   Tie Line 969-6044;  Phone (905) 413-6044
mailto:zongaro@ca.ibm.com