Re: [xsl] Sibling axis and as="element()"

Subject: Re: [xsl] Sibling axis and as="element()"
From: David Carlisle <davidc@xxxxxxxxx>
Date: Mon, 31 Jul 2006 16:21:07 +0100
> Is this the case?  Do parentless trees lose their axes?
if you aint got a parent you aint got a brother, it's just a matter of
biology:-)

If you use xsl:variable with content and no as attribute then (for xslt1
compatibility) an implict document node is created, and any nodes
generated are made children of that document node, so as a consequence
of that they become siblings of each other.

If you use an as attribute then the implict document node is not
generated and the result is a sequence. In your case the sequence is of
newly constructed, parentless nodes so they are not siblings.  In this
case they have no siblings at all, but in other cases they could have
siblings but not in the variable.

If your input looks like

<x>
<a><b/></c/></a>
<a><b/></c/></a>
<a><b/></c/></a>
</x>

and your variable looks like

<xsl:variable name="x"  as="element()*">
 <xsl:sequence select="/x/a/b"/>
</xsl:variable>

then the $x is the same as if you'd have gone


<xsl:variable name="x" select="/x/a/b"/>

and (as in 1.0) you'd have a sequence of 3 b elements, and they'd all have
siblings which are c elements which are not in the sequence (aka node
set)  bound to the variable.

David

Current Thread