<xsl:variable> scope

Discussion in 'XML' started by Xeon, Jul 1, 2003.

  1. Xeon

    Xeon Guest

    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
     
    Xeon, Jul 1, 2003
    #1
    1. Advertising

  2. Xeon

    Marrow Guest

    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




    "Xeon" <> wrote in message
    news:...
    > 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
     
    Marrow, Jul 2, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Karsten Weinert
    Replies:
    3
    Views:
    1,031
    Karsten Weinert
    Jul 5, 2004
  2. Replies:
    1
    Views:
    3,639
    A. Bolmarcich
    May 27, 2005
  3. Hoi Wong
    Replies:
    8
    Views:
    1,127
    P. Lepin
    Feb 21, 2008
  4. David Filmer
    Replies:
    19
    Views:
    260
    Kevin Collins
    May 21, 2004
  5. Andrew Falanga
    Replies:
    2
    Views:
    206
    Andrew Falanga
    Nov 22, 2008
Loading...

Share This Page