xsl-list
[Top] [All Lists]

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

2005-09-01 00:49:07
Tempore 09:07:07, die 09/01/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Mikael Petterson (KI/EAB) 
<mikael(_dot_)petterson(_at_)ericsson(_dot_)com>:

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[(_at_)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)
«There are only 10 types of people in this world. Those who understand binary, and 
those who don't»

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>