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

RE: Assigning value to variable based on xsl:choose te

Subject: RE: Assigning value to variable based on xsl:choose test
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 24 Jul 2006 10:08:54 +0100
assigning value to variable xslt
This is a FAQ. The problem with your code is that instead of creating one
variable with two possible values, it creates two different variables, and
of course they both go out of scope. The solution is

<xsl:variable name="X">
    <xsl:when test="....">8</xsl:when>
    <xsl:when test="....">4</xsl:when>

In XSLT 2.0 you can also write

<xsl:variable name="X" select="if (...) then 8 else 4"/>

I've no idea where xsl:attribute might come into the picture, but perhaps
that's best not asked. xsl:attribute is an instruction that creates
attribute nodes in the result tree.

Michael Kay


> -----Original Message-----
> From: David Murphy [mailto:david@xxxxxxxxxxxxxx] 
> Sent: 24 July 2006 10:08
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Assigning value to variable based on xsl:choose test
> Hello
> Is it possible to set the value of a variable based upon a test?
> My first effort is below, and I also tried to assign the 
> value to the variable using xsl:attribute but that doesn't 
> work either.
> <xsl:choose>
> 	<xsl:when test="price_type = 56"><xsl:variable name="numTickets"
> select="8"/></xsl:when>
> 	<xsl:when test="price_type = 57"><xsl:variable name="numTickets"
> select="4"/></xsl:when>
> 	<xsl:otherwise><xsl:variable name="numTickets"
> select="9"/></xsl:otherwise>
> </xsl:choose>
> ...
> <xsl:call-template name="counter">
>       <xsl:with-param name="max" select="$numTickets"/> 
> </xsl:call-template>
> I'm guessing that one cannot assign values to variables 
> inline like this, but I've not managed to get it working so a 
> bit of guidance that will help me work this out would be much 
> appreciated.
> Regards, David

Current Thread


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.
First Name
Last Name
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.