xsl-list
[Top] [All Lists]

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

2003-01-28 12:55:15
-----Original Message-----
From:     "Hubert Holtz" <Turnhose_alt(_at_)gmx(_dot_)net>

<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(_at_)onebox(_dot_)com - email


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