Xslt 1.0 has been designed based on the best intentions. Xslt 2.0 got a legacy baggage.
If you're not entirely concentrated during translation of your algorithms into xslt 2.0 you can get into trap, as we did.
Consider a code snapshot:
<xsl:variable name="elements" as="element()+"> <xsl:apply-templates/> </xsl:variable> <xsl:variable name="converted-elements" as="element()+" select="$elements/t:convert(.)"/>
Looks simple, isn't it?
Our intention was to get converted elements, which result from some xsl:apply-templates logic.
xsl:apply-templates
Well, this code works... but rather sporadically, as results are often in wrong order! This bug is very close to what is called a Heisenbug.
So, where is the problem?
Elementary, my dear Watson:
$elements/t:convert(.)
Here is a tricky part:
The relative order of nodes in distinct trees is stable but implementation-dependent...
Clearly each rootless element belongs to a unique tree.
After that we have realized what the problem is, code has been immediately rewritten as:
<xsl:variable name="elements" as="element()+"> <xsl:apply-templates/> </xsl:variable> <xsl:variable name="converted-elements" as="element()+" select=" for $element in $elements return t:convert($element)"/>
P.S. Taking into an accout a size of our xslt code base, it took a half an hour to localize the problem. Now, we're at position to review all uses of slashes in xslt. As you like it?
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u