[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] value of variable inside a condition doesn't work?


Subject: RE: [xsl] value of variable inside a condition doesn't work?
From: cknell@xxxxxxxxxx
Date: Tue, 28 Jan 2003 14:55:15 -0500

> -----Original Message-----
> From:     "Hubert Holtz" <Turnhose_alt@xxxxxxx>
>
> <xsl:if test="($lang)='1' ">
>    <xsl:variable name="stadt" select="Stadt"/>
>     <xsl:variable name="Texteingabe" select="Hier Text eingeben"/>
>    <xsl:variable name="berichtstatus" select="aktuell"/>
> </xsl:if>
>
> <xsl:if test="($lang)='2' ">
>    <xsl:variable name="stadt" select="city"/>
>    <xsl:variable name="Texteingabe" select="Please enter text"/>
>    <xsl:variable name="berichtstatus" select="current"/>
> </xsl:if>
> 
> ..
> 
> <td><xsl:value-of select="$stadt"/></td>
>
> -- code --

You have two problems:

1) When you assign a literal string to a variable, you must doubly quote the string, thus:

<xsl:variable name="stadt" select="'city'"/>

not as you have done:

<xsl:variable name="stadt" select="city"/>

2) A variable exists only within the scope where it was defined. Once you exit that scope (in your example, once the transformation exits the <xsl:if> element) the variable ceases to exist. You have two choices here:

2a) Put all the relevant templates and elements inside each <xsl:if> element.

2b) Define the templates once and invoke them inside each <xsl:if> by using <xsl:apply-templates> or <xsl:call-template>.


-- 
Charles Knell
cknell@xxxxxxxxxx - email


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



Current Thread