Re: [xsl] RE: Returning A Tree

Subject: Re: [xsl] RE: Returning A Tree
From: "Swen Thuemmler" <Swen.Thuemmler@xxxxxxxxxxxx>
Date: Thu, 6 Sep 2001 10:51:26 +0200 (CEST)
On Wed, 5 Sep 2001, Darren Hayduk wrote:

> OK, here is an example.
> <xsl:template name="selectNodes">
>   <xsl:param name="doWhat"/>
>   <xsl:choose>
>      <xsl:when test="$doWhat='GiveMeA'">
>         <xsl:for-each select="//A">
>            <xsl:value-of select="."/>
This only gives you a text node with the string value of A.
>         </xsl:for-each>
>      </xsl:when>
>      <xsl:when test="$doWhat='GiveMeB'">
>         <xsl:copy-of select="//B"/>
Ok, here you have a node-set.
>      </xsl:when>
>   </xsl:choose>
> </xsl:template>

Now, you can't return a node-set with call-template, so your variable now contains
a result tree fragment (when you use xsl:copy-of select="$B", you get:

Now in XSL1.0, the only thing you can do with a node set is converting it to a
string or copy it to the current output destination. But some processors have
an extension function, which allows you to convert this to a node-set (containing
a single synthetic root node which has in your case the B nodes as children)
[Note: this is just my understanding, I might be wrong here].
You could then do something like (I think):

  <xsl:for-each select="saxon:node-set($B)/B">
     <xsl:value-of select="."/>
     <xsl:if test="not(position()=last())">

But newer processors seemt to do the conversion themselves (in anticipation of
the changes in XSL-1.1 (or 2.0), so with Saxon 6.4 I can also say:

  <xsl:for-each select="$B/B">
     <xsl:value-of select="."/>
     <xsl:if test="not(position()=last())">

Hope this helps


 XSL-List info and archive:

Current Thread