<xsl:variable> scope

X

Xeon

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>
<xsl:eek:therwise>
<xsl:variable name="test" select="1"/>
</xsl:eek:therwise>
</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
 
M

Marrow

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>
<xsl:eek:therwise>
<xsl:text>1</xsl:text>
</xsl:eek:therwise>
</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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top