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

RE: Adding Variables

Subject: RE: Adding Variables
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Mon, 28 Jun 2004 12:43:41 +0100
adding variables
> Hi All,
> I've created a number of xsl variables in my template
> and I now wish to add these variables together and
> render the result in my template. For example,
> 
> <xsl:variable name="num1">
> <xsl:value-of select="//test1/somevalue1"/>
> </xsl:variable>
> 
> and
> 
> <xsl:variable name="num2">
> <xsl:value-of select="//test2/somevalue2"/>
> </xsl:variable>
> 
> Trying <xsl:value-of select="$num1+$num2"/> doesn't
> work.
> 

What do you mean by "it doesn't work"? There's nothing wrong with your code,
though it will produce NaN if the variables aren't numeric.

However, try to get out of the habit of:

<xsl:variable name="num1">
  <xsl:value-of select="//test1/somevalue1"/>
</xsl:variable>

It's an absurdly long-winded and inefficient way of doing:

<xsl:variable name="num1" select="//test1/somevalue1"/>

(The compiler can't automatically convert one to the other, because some
expressions treat them differently, for example boolean($num1) is always
true in the first case, but in the second case it is true only if
//test1/somevalue1 selects at least one node).

Michael Kay


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.