Can anyone explain this to me? (using latest libxslt):
<a><xsl:copy-of select="(@attrib|exsl:node-set(0))"/></a>
<b><xsl:copy-of select="(@attrib|exsl:node-set(0))[position()=1]"/></b>
<x><xsl:copy-of select="(@attrib|exsl:node-set(0))[1]"/></x>
<xsl:variable name="value" select="@attrib"/>
<y><xsl:copy-of select="($value|exsl:node-set(0))[1]"/></y>
Result (for @attrib = 1 at current node):
<a attrib="1">0</a>
<b attrib="1"/>
<x>0</x>
<y attrib="1"/>
<a>
and <b>
show expected behavior.
<x>
is IMHO incorrect.
But why does putting @attrib
into a variable "fix" it for <y>
?
BTW: Everything is correct when @attrib is
not present. The copy-of used here is for debugging; original usage converts the XPath result to a number, and a missing attribute shall not lead to NaN, but a certain default value.