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.
ext:node-set()on a scalar (non-node-set or non-RTF) argument. In this case the created node is in its separate document and there is no ordering defined between this node and nodes of other documents -- meaning that it may come as first or last, and this is unpredictable. Also note, that no otherxxx:node-set()extension accepts a scalar argument. Even some implementations ofext:node-set()reject a scalar argument as error: Saxon 6.5.4: "Error at xsl:copy-of on line 7 of file:/(Untitled): exslt:node-set(): argument must be a node-set or tree" - Dimitre Novatchev<xsl:variable name="default">0</xsl:variable>and$defaultinstead of0does not change much. - smilingthaxxsl:variableresides in the stylesheet document and thearrtibattribute resides inthe source XML document. There is no ordering defined between nodes that reside in two different XML documents. XPath 1.0 doesn't have sequences, as XPath 2.0 and as you have found, sequences cannot be modelled easily. - Dimitre Novatchev[1]and[position()=1](i.e.<b>and<x>)? - smilingthax[1]and[position() = 1]the former must be interpreted as a shorthand for the latter. This is as per XPath 1.0 spec: "the result is a number, the result will be converted to true if the number is equal to the context position and will be converted to false otherwise; Thus a location path para[3] is equivalent to para[position()=3]. " see: w3.org/TR/xpath/#predicates - Dimitre Novatchev