This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: How can I use a variable out of it scope ?
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] How can I use a variable out of it scope ?
- From: "frank Stein" <freeposte at hotmail dot com>
- Date: Wed, 31 Jan 2001 10:12:07
- Reply-To: xsl-list at lists dot mulberrytech dot com
> > I would like to use a variable out of it scope.
>
>You can't.
I understand.
>If you said what you were trying to do at a higher level, perhaps
>someone may suggest how it would be done more naturally in XSLT.
>
I'm using the following XML input document :
...
<Level_1 Name="Name_1">
...
</Level_1>
...
<Level_1 Name="Name_n">
<Level_2 Name="Name_2">
</Level_2>
...
<Level_2 Name="Name_n">
</Level_2>
...
</Level_1>
...
The following code puts on "my_var" the totality of the Name attributes of
each element "Level_1" :
<xsl:template match="Level_1">
<xsl:variable name="my_var">
<xsl:for-each select="Level_2">
<xsl:value-of select="./@Name"/>
</xsl:for-each>
</xsl:variable>
<xsl:apply-template/>
</xsl:template>
Now myvar contains "Name_1Name_2...Name_n..." as a string.
And I want to use it on the Level_2 match:
<xsl:template match="Level_2">
<!-- Here I would like to use my_var but I can't cause I'm out of "my_var"
scope -->
<!-- Do you know how can I recover "Name_1Name_2...Name_n..." ? -->
</xsl:template>
>From: David Carlisle <davidc@nag.co.uk>
>Reply-To: xsl-list@lists.mulberrytech.com
>To: xsl-list@lists.mulberrytech.com
>Subject: Re: [xsl] How can I use a variable out of it scope ?
>Date: Wed, 31 Jan 2001 09:28:00 GMT
>
> > I would like to use a variable out of it scope.
>
>You can't.
>
>
> > <xsl:template match="level_2">
> > <!-- How could I use "my_var" ? -->
> > </xsl:template>
>
>Some processors have extension functions that allow this (saxon:assign
>being one of the guilty parties) but the design of XSLT is totally
>influenced by the fact that it is a side effect free language.
>
>It's not that imperative programming is necessarily evil, but if you
>want to program in that style it makes more sense to use a language that
>has assignment statements (omnimark, perl, ....) rather than trying to
>twist a language that does not.
>
>If you said what you were trying to do at a higher level, perhaps
>someone may suggest how it would be done more naturally in XSLT.
>
>David
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list