Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > <xsl:variable> scope

Reply
Thread Tools

<xsl:variable> scope

 
 
Xeon
Guest
Posts: n/a
 
      07-01-2003
Hi,

I'm trying this code snippet below but the parser (sablotron) returns
error :

<xsl:choose>
<xsl:when test="some test case">
<xsl:variable name="test" select="0"/>
</xsl:when>
<xsltherwise>
<xsl:variable name="test" select="1"/>
</xsltherwise>
</xsl:choose>

<xsl:value-of select="$test"/>

Sablotron whines that $test is undefined. IMHO the scope of $test is
only inside <xsl:choose>. How can I overcome this?

Note: the structure of the code is a simplified one. I could put the
<xsl:value-of> element inside the <xsl:choose> but it would increase
the complexity of the overall code, not to mention readablity.

TIA
 
Reply With Quote
 
 
 
 
Marrow
Guest
Posts: n/a
 
      07-01-2003
Hi,

No, the variable is definitely out of scope at the point you are trying to
use it.

You need to wrap the <xsl:choose> within the <xsl:variable>, e.g.

<xsl:variable name="test">
<xsl:choose>
<xsl:when test="some test case">
<xsl:text>0</xsl:text>
</xsl:when>
<xsltherwise>
<xsl:text>1</xsl:text>
</xsltherwise>
</xsl:choose>
</xsl:variable>

<xsl:value-of select="$test"/>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator




"Xeon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> Hi,
>
> I'm trying this code snippet below but the parser (sablotron) returns
> error :
>
> <xsl:choose>
> <xsl:when test="some test case">
> <xsl:variable name="test" select="0"/>
> </xsl:when>
> <xsltherwise>
> <xsl:variable name="test" select="1"/>
> </xsltherwise>
> </xsl:choose>
>
> <xsl:value-of select="$test"/>
>
> Sablotron whines that $test is undefined. IMHO the scope of $test is
> only inside <xsl:choose>. How can I overcome this?
>
> Note: the structure of the code is a simplified one. I could put the
> <xsl:value-of> element inside the <xsl:choose> but it would increase
> the complexity of the overall code, not to mention readablity.
>
> TIA



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Lexical scope vs. dynamic scope Xah Lee Java 0 02-26-2009 10:08 AM
CSPEC issue: lossing scope (or incorrect scope) in cspec subroutine. balldarrens@gmail.com Perl Misc 0 02-05-2009 08:42 PM
Scope - do I need two identical classes, each with different scope? ann Java 13 09-13-2005 03:07 AM
How do namespace scope and class scope differ? Steven T. Hatton C++ 9 07-19-2005 06:07 PM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM



Advertisments