[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Question about variable definition and types


Subject: Re: [xsl] Question about variable definition and types
From: David Carlisle <davidc@xxxxxxxxx>
Date: Fri, 7 Mar 2008 15:10:26 GMT

> If I process the content of $a2 I would assume that preceding/ 
> following-sibling axis only "sees" the siblings in the variable.

No, it will go off and traverse the original document.
The same feature was present in XSLt 1.

Going

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

Is exactly the same as going

 <xsl:variable name="a2" select="a"/>

which even in xslt1 stores a set of a nodes in their original context.

the only new feature is that in xslt2 you can use the content of
xsl:variable as an alternative to the select attribute, which gives the
possibility of using control constructs such as xsl;choose, not so
easily available in xpath.

this feature of allowing content as an alternative to select attribute
is a general feature of xslt2, see xsl:attribute, xsl:value-of etc.
The only complication was xsl:variable where content was already alowed
(but with the different semantics of implying a document node) so here
the
"new style" semantics of the content being a replacement for the select
expression only applies when there is an as attribute.


> How would I access the preceding/following siblings from "inside" the  
> variable with the as attribute?

If you want the nodes inside the variable to be siblings (and have no
other siblings) then you need to copy them rather than refer to the
original nodes. The siblings of a node are a property of that node
so if you want a node which has different siblings, you don't want to
refer to the original node, you need a copy.


David


Current Thread
Keywords