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

Re: Cannot get numeric value - what am I doing wrong?

Subject: Re: Cannot get numeric value - what am I doing wrong?
From: Brian Chrisman <brian.chrisman@xxxxxx>
Date: Thu, 18 Mar 2004 14:27:38 +0100
numeric value
Kyle Partridge wrote:

Hi all,

This is probably an easy question for you to answer, but I'm stumped.

I've got this variable I'm trying to assign a NUMERIC value to:



Unless you are doing a xsl:value-of (or a few other things), you are getting back nodes from xpath expressions.
You can call /my/path/to/node/text() to get the actual value in xpath format.


You can also do <xsl:value-of select="sum(/my/path/to/number)"/>
To return the sum off all numbers in the 'number' nodes.


<xsl:variable name="top-remove">
	<xsl:choose>
		<xsl:when test="string($prior-break-regions)">
			<xsl:call-template name="add-up">
				<xsl:with-param name="set-one"
select="$prior-break-regions/@top"/>
				<xsl:with-param name="set-two"
select="$prior-break-regions/@height"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise><xsl:value-of
select="number('0')"/></xsl:otherwise>
	</xsl:choose>
</xsl:variable>

It calls a template, "add-up" which takes two sets of number node-sets
and adds them all together.  This, too, is supposed to return a NUMERIC
value:

<xsl:template name="add-up">
	<xsl:param name="set-one"/>
	<xsl:param name="set-two"/>
	<xsl:param name="index" select="1"/>
	<xsl:param name="total" select="0"/>
	<xsl:choose>
		<xsl:when test="$index &gt; count($set-one) or $index
&gt; count($set-two)">
			<xsl:value-of select="number($total)"/>
		</xsl:when>
		<xsl:otherwise>
			<xsl:call-template name="add-up">
				<xsl:with-param name="set-one"
select="$set-one"/>
				<xsl:with-param name="set-two"
select="$set-two"/>
				<xsl:with-param name="total"
select="$total + $set-one[$index] + $set-two[$index]"/>
				<xsl:with-param name="index"
select="$index + 1"/>
			</xsl:call-template>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

So...HOW COME I wind up with a Node-Fragment type assigned to my
variable, when all is said and done???  I need the value to be a numeric
value, so that when I test to see if it is boolean true or false, it
will react properly.

Thanks,
KP


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




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.