xsl-list
[Top] [All Lists]

RE: invalid xpath expression

2003-05-28 11:23:33
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:choose>
    <xsl:when test=".=list">12</xsl:when>
etc.
</xsl:variable>
<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.

Lars


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>