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 11:43:09 GMT
> So
> 
> <xsl:variable name="foo" as="document-node()">
>    <a/>
>    <b/>
> </xsl:variable>
> 
> would be the equivalent of (identical to?) an un-typed variable and  
> allow siblings?

No you get a type error in that case, that you have specified a document
node but generated element nodes (the document node generation is only
implicit in the "legacy" usage without an as)

You'd need to do

<xsl:variable name="foo" as="document-node()">
<xsl:document>
   <a/>
   <b/>
</xsl:document>
</xsl:variable>

To explictly make the node.


But the main difference between the usage with and without as= is not
that the nodes in teh variable are siblings, it's that they are (or are
not) copies.

If you go

<xsl:variable name="a1">
  <xsl:sequence select="a"/>
</xsl:variable>


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



Then in both cases the a element nodes are siblings, but 

in $a1 they are _copies_ of nodes from the input copied into a new
temporary tree and so are the only siblings of the new / node at the top
of that tree.

in $a2 they are the original a nodes in the source document (so
necessarily siblings as they are selected by the xpath "a" so all
children of the current node at that point. In this case $a2 holds these
nodes, and they are (still) siblings, but they may have other siblings
not contained in the variable, and their parent node is similarly not
cotained in the variable. 

David

Current Thread