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

Re: help to get data before '%' of 'value' attribute

Subject: Re: help to get data before '%' of 'value' attribute in element 'coverage'
From: "Joris Gillis" <roac@xxxxxxxxxx>
Date: Thu, 01 Sep 2005 09:49:07 +0200
my value
Tempore 09:07:07, die 09/01/2005 AD, hinc in xsl-list@xxxxxxxxxxxxxxxxxxxxxx scripsit Mikael Petterson (KI/EAB) <mikael.petterson@xxxxxxxxxxxx>:

How can I get the values 0 , 15 and 25 and 'add' the together?

You're making it more complicated than necessary by supplying source XML and source values that disagree...


In XLST 1.0, there is no compact one-liner to solve this, you'll need to invent some recursive addition mechanism.

<xsl:variable name="measure">
	<xsl:call-template name="summer">
		<xsl:with-param name="nodes" select="report/data/all/package/coverage[@type='block, %']/@value"/>
	</xsl:call-template>
</xsl:variable>
Value of fpx: <xsl:value-of select="$measure"/>



The template 'summer' takes care of the summing:

<xsl:template name="summer">
<xsl:param name="nodes"/>
<xsl:param name="sum" select="0"/>

<xsl:variable name="my-node" select="$nodes[1]"/>
<xsl:variable name="my-value" select="number(substring-before($my-node,'%'))"/>
<xsl:choose>
	<xsl:when test="count($nodes)!=0">
		<xsl:call-template name="summer">
			<xsl:with-param name="nodes" select="$nodes[position()!=1]"/>
			<xsl:with-param name="sum" select="$sum + $my-value"/>
		</xsl:call-template>
	</xsl:when>
	<xsl:otherwise>
		<xsl:value-of select="$sum"/>
	</xsl:otherwise>
</xsl:choose>
</xsl:template>

(Note that, as a consequence of some weird bug I just discovered in my XSLT engine, I have not been able to test this properly, I'm pretty confident, though, that it will work with any other xslt engine.)

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
B+There are only 10 types of people in this world. Those who understand binary, and those who don'tB;

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.