RE: [xsl] return nodeset to xsl:variable

Subject: RE: [xsl] return nodeset to xsl:variable
From: "Evan Lenz" <elenz@xxxxxxxxxxx>
Date: Wed, 7 Mar 2001 16:02:15 -0800
Well, you can use the select attribute of xsl:variable like so:

<xsl:variable name="x" select="foo/bar"/>

$x will return the node-set selected by the above XPath expression.

But if you want to create an arbitrary node-set (not from the original
source document), you can't do that without an extension function. This is
because the content of xsl:variable (and named templates, etc.) only
instantiates a result tree fragment (RTF), which is what you're doing when
you "return a string". However, most XSLT processors provide an extension
that allows you to access that result tree fragment as a node-set.

For example:

<xsl:variable name="x">
  <foo>
    <bar>my bar</bar>
    <xsl:copy-of select="bar"/>
  </foo>
</xsl:variable>

You could then do something like this:

<xsl:apply-templates select="saxon:node-set($x)/foo/bar"/>

Note that the node-set identified by saxon:node-set($x) is a node-set
containing only one node, namely the root node of a new tree. From that
root, you can drill down into the tree, as in the above XPath expression.

XSLT 1.1 will take away the need for the node-set extension function so that
you will always be able to access arbitrarily constructed trees as node-sets
(that contain one root node). This eliminates the RTF type from XSLT. You'll
be able to do, simply:

<xsl:apply-templates select="$x/foo/bar"/>

While this effectively enables you to access arbitrarily constructed nodes,
it doesn't really allow you complete freedom in arbitrary node-set
construction, because it always returns just one newly-constructed root
node. Since it only contains the root node of a new tree, it can't, by
itself, return a node-set that also contains nodes from the source tree.

I think that the other discussions on this list regarding "EXSLT" begin to
address this issue. There's a desire for a user-defined function mechanism
that might return arbitrarily-constructed node-sets.

For many use cases, however, a node-set() extension function (and later,
XSLT 1.1) should be all you need.

Hope this helps,

Evan Lenz
XYZFind Corp.

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Paul Bell
> Sent: Wednesday, March 07, 2001 3:19 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] return nodeset to xsl:variable
>
>
> Hi All,
>
> I see how to set an xsl:variable by 'returning' a string from a called
> template, but how do you return a node set to an xsl:variable?.
>
> Cordially,
>
> Paul
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread