[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: max of sum

Subject: Re: max of sum
From: Oliver Becker <obecker@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 1 Feb 2002 09:10:08 +0100 (MET)
Re:  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@xxxxxxxxxxxxxxxxxxxxxxx             |
|  op|qo        WWW:    http://www.informatik.hu-berlin.de/~obecker |
\-------------------------------------------------------------------/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread
  • Re: max of sum
    • Oliver Becker - Fri, 1 Feb 2002 03:07:45 -0500 (EST) <=
      • Charly - Fri, 1 Feb 2002 09:30:48 -0500 (EST)

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.