Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "Joris Gillis" <roac@---------->
To:
Date: 9/1/2005 7:48:00 AM
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;


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent