RE: [xsl] xsl:variable?

Subject: RE: [xsl] xsl:variable?
From: "Martinez, Brian" <brian.martinez@xxxxxxxxxxx>
Date: Wed, 26 Nov 2003 10:15:06 -0700
> From: Nicolas Toper [mailto:ntoper@xxxxxxxx]
> Sent: Wednesday, November 26, 2003 9:45 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] xsl:variable?
> 
> 
> Hi,
> 
> I'm trying to put a node-set in a a variable but I can't make 
> it work...
> 
> Here is a snippet of my code:
> 
> <xsl:variable name="t">
> <a href=".."><xsl:value-of select="y"></a>
> 
> </...
> 
> <xsl:value-of select="concat($t,...)...
> 
> I get only y as an output. Any idea please?

Assuming you're working with XSLT 1.0, this is an extreme FAQ.  Variables
that contain template bodies always return a result tree fragment (RTF)--and
there is no way to cast such variables to a node-set without resorting to
the node-set() extension function that's available with most processors.

One way to fix this would be to use a select attribute on the variable:

<xsl:variable name="t" select="y"/>

Assuming y is a valid node in your input, you can now write:

<a href="..."><xsl:copy-of select="$t"/></a>

copy-of will write $t including its child nodes to the result tree; value-of
will only copy its textual content--child elements are ignored.

hth,
b.

| brian martinez                           brian.martinez@xxxxxxxxxxx |
| lead gui programmer                                    303.357.3548 |
| cheap tickets, part of trip network                fax 303.357.3380 |
| 6560 greenwood plaza blvd., suite 400           englewood, co 80111 |
| cendant travel distribution services   http://www.cheaptickets.com/ |

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


Current Thread