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 17:42:31 +0100
>  but that do not have a common parent? 
no now they _do_ have a common parent, the document node you generated
with xsl:document.

maybe take a step back. Conceptually the content of xsl:template,
literal result elements xsl:variable etc are all "template bodies" and
are all evaluated the same way (and as attribute does not affect this)
so a content of

	<foo/>
	<foo/>
	<foo/>

generates a sequence of three parentless foo nodes.

Now what happens to the "content sequence" depends of what its content
of, but the _usual_ thing is that boring details like text nodes being
merged happens, and then all nodes are _copied_ to be child nodes of the
containing node in the current result tree.

so in
<bar>
	<foo/>	<foo/>	<foo/>
</bar>
those three foo nodes are copied to be children of bar and at that point
become siblings. (The system probably doesn't really copy them as it
knows in advance the parentless nodes will never be accessed so it
probably can immediately attach them to bar but that's implementation
details )

the situation in

<xsl:document>	<foo/>	<foo/>	<foo/> </xsl;document>
is exactly the same  except now they become children of a / node rather
than an element.

If you have 
<xsl:variable name="foo">
	<xsl:document>
		<foo/>
		<foo/>
		<foo/>
	</xsl:document>
</xsl:variable>

then first you generate the content sequence which in this case is a
sequence of one / node (which happens to have some foo children, but
that does not matter here) then you copy this sequence in as children of
the implict / node, except there is a special rule about copying /
nodes, in that (same as in xslt 1.0) the node itself is not copied, but
rather its children are copied 9as you can not have / being a child
node).

If you have 
<xsl:variable name="foo" as=document-node()>
	<xsl:document>
		<foo/>
		<foo/>
		<foo/>
	</xsl:document>
</xsl:variable>

Then the content sequence is generated as above, and as that is a
seuence of one / node, it matches the specified type and so is accepted,
no copying is done in this case.

David

Current Thread