RE: [xsl] xsl:if @attribute + xsl:variable not working

Subject: RE: [xsl] xsl:if @attribute + xsl:variable not working
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 28 Nov 2001 09:29:05 -0000
> why if
>
>     <xsl:if test="@position = 1">
>       <xsl:variable name="color" select="'#FFF7A0'"/>
>     </xsl:if>
>     <xsl:if test="@position = 2">
>       <xsl:variable name="color" select="'#FF980F"/>
>     </xsl:if>
>
> I get this?
>
> "A reference to variable or parameter 'colortabla' cannot be resolved.
> The variable or parameter may not be defined, or it may not
> be in scope."
>
> -> the variable IS in scope (if I define it without xsl:if it works)
> xml -> <area position="1"> or <area position="2">
>

No, the variable isn't in scope. A variable is in scope only for elements
that are following-siblings, or descendants of following-siblings, of the
<xsl:variable> element. Your <xsl:variable> elements have no following
siblings.

Use
<xsl:variable name="color">
  <xsl:choose>
  <xsl:when test="@position = 1">#FFF7A0</xsl:when>
  <xsl:when test="@position = 2">#FF980F</xsl:when>
  </xsl:choose>
</xsl:variable>

Mike Kay


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


Current Thread