<xsl:variable> scope

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Xeon

    #1

    <xsl:variable> scope

    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:otherwis e>
    <xsl:variable name="test" select="1"/>
    </xsl:otherwise>
    </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

    #2
    Re: &lt;xsl:variabl e&gt; scope

    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:otherwis e>
    <xsl:text>1</xsl:text>
    </xsl:otherwise>
    </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" <xdblade@zworg. com> wrote in message
    news:78321f06.0 307011456.46d53 313@posting.goo gle.com...[color=blue]
    > 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:otherwis e>
    > <xsl:variable name="test" select="1"/>
    > </xsl:otherwise>
    > </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[/color]


    Comment

    Working...