[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

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

Subject: RE: value of variable inside a condition doesn't work?
From: cknell@xxxxxxxxxx
Date: Tue, 28 Jan 2003 14:55:15 -0500
xsl if condition variable
> -----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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.