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

[xsl] Re: How to store a node in a local variable using if or when


Subject: [xsl] Re: How to store a node in a local variable using if or when
From: "Dimitre Novatchev" <dnovatchev@xxxxxxxxx>
Date: Fri, 1 Aug 2003 07:11:43 +0200

Use:

  <xsl:variable name="myV" select="/a/b/c[condition1] | /c[condition2]"/>

This assumes that condition1 and condition2 are mutually exclusive.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



"Néstor Boscán" <nestor.boscan@xxxxxxxxxx> wrote in message
news:001c01c357d0$38e1c4c0$bd3554c8@xxxxxxxxxx
> Hi
>
> I would like to process information from a node that can come from two
> different places in the XML tree. Because the processing is the same I
> create a variable and with a choice element I will set the variable to
> one of the two nodes. So I can figure out only two ways of doing it that
> doesn't work. Here are the two examples:
>
> First example use <xsl:value-of>:
>
> <xsl:variable name="node"/>
>     <xsl:choose>
>         <xsl:when test="condition1">
>             <xsl:value-of select="/a/b/c"/>
>         </xsl:when>
>         <xsl:when test="condition2">
>             <xsl:value-of select="/c"/>
>         </xsl:when>
>     </xsl:choose>
> </xsl:variable>
>
> <xsl:for-each select="$node">
>     process
> </xsl:for-each>
>
> Will not work because <xsl:value-of> only selects strings not nodes. So
> <xsl:variable name="node" select="path"/> is not the same as
> <xsl:variable name="node"><xsl:value-of select="path"/></xsl:variable>
>
> Second example use "select" attribute in variable:
>
> <xsl:choose>
>     <xsl:when test="condition1">
>         <xsl:variable name="node"  select="/a/b/c"/>
>     </xsl:when>
>     <xsl:when test="condition2">
>         <xsl:variable name="node"  select="/c"/>
>     </xsl:when>
> </xsl:choose>
> </xsl:variable>
>
> <xsl:for-each select="$node">
>     process
> </xsl:for-each>
>
> Will not work because variable "node" is out of scope.
>
> Any ideas?
>
>
>
>  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
Keywords
xml