RE: [xsl] invalid xpath expression

Subject: RE: [xsl] invalid xpath expression
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Wed, 28 May 2003 13:23:33 -0500
> my xsl file is:
> <xsl:choose>
> <xsl:when test=".=list">
> <xsl:variable name="n" select="12"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:variable name="n" select="2"/>
> </xsl:otherwise>
> </xsl:choose>
> -------------------
> <xsl:variable name="m" select="$n"/>
> i receive the error :invalid xpath expression!
> so what the problem in <xsl:variable name="m" select="$n"/>?

A variable is only in scope in the element in which it is declared.
So the first n is only in scope within the first <when>.
The second n is only in scope within the <otherwise>.
No n is in scope for your select="$n".

To fix the problem, put the <choose> inside the <variable name="n">:

<xsl:variable name="n">
    <xsl:when test=".=list">12</xsl:when>
<xsl:variable name="m" select="$n" />

This is a kind of thing that is usually taught in introductory
textbooks for XSLT, such as Jeni Tennison's.


 XSL-List info and archive:

Current Thread