|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








