[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
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;
|
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
|