Re: [xsl] help to get data before '%' of 'value' attribute in element 'coverage'

Subject: Re: [xsl] 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
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"/>
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: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:value-of select="$sum"/>

(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.)

Joris Gillis (
B+There are only 10 types of people in this world. Those who understand binary, and those who don'tB;

Current Thread