This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: max of sum
- From: "Charly" <cohana at investacorp dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Fri, 1 Feb 2002 09:33:18 -0800
- Subject: Re: [xsl] max of sum
- References: <200202010810.g118A8906457@mail.informatik.hu-berlin.de>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Thanks Oliver,
That's awesome .
----- Original Message -----
From: "Oliver Becker" <obecker@informatik.hu-berlin.de>
To: <xsl-list@lists.mulberrytech.com>
Sent: Friday, February 01, 2002 12:10 AM
Subject: Re: [xsl] max of sum
> > Is there a way to get the max for a bunch of sum on an attribute.
>
> Yes, of course.
>
> > I have the following XML and would like to find what's the highest
expenses
> > (sum of all expense/@value). Which would be 303 .
> > any idea ?
> >
> > <company>
> > <department id="IT">
> > <expense value="10"/>
> > <expense value="12"/>
> > <expense value="13"/>
> > <expense value="18"/>
> > <expense value="28"/>
> > </department>
> >
> > <department id="Research">
> > <expense value="40"/>
> > <expense value="150"/>
> > <expense value="75"/>
> > <expense value="17"/>
> > <expense value="21"/>
> > </department>
> >
> > <department id="Finance">
> > <expense value="34"/>
> > <expense value="77"/>
> > </department>
> >
> > <department id="HR">
> > <expense value="22"/>
> > </department>
> > </company>
>
>
> <xsl:template match="department">
> <xsl:variable name="sum" select="sum(expense/@value)" />
> <xsl:if test="not(../department[sum(expense/@value) > $sum])">
> <xsl:text />max: <xsl:value-of select="$sum" /> for <xsl:text />
> <xsl:value-of select="@id" />
> </xsl:if>
> </xsl:template>
>
> Cheers,
> Oliver
>
>
> /-------------------------------------------------------------------\
> | ob|do Dipl.Inf. Oliver Becker |
> | --+-- E-Mail: obecker@informatik.hu-berlin.de |
> | op|qo WWW: http://www.informatik.hu-berlin.de/~obecker |
> \-------------------------------------------------------------------/
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list