xsl-list
[Top] [All Lists]

RE: for-each and summing based on group

2005-01-05 02:50:43
First read up about standard grouping techniques such as Muenchian grouping
at http://www.jenitennison.com/xslt/grouping

Computing a subtotal for each group is then a minor variant of the
technique: instead of merely iterating over the items in the group using
xsl:for-each, you can assign the node-set comprising the group to a
variable, and then sum over that using the sum() function.

Like all grouping problems, it's much easier in 2.0:

<xsl:for-each-group select="rows" group-by="columnA">
  <xsl:apply-templates select="current-group()"/>
  <subtotal><xsl:value-of select="sum(current-group()/columnB)"/></subtotal>
</xsl:for-each-group>

Michael Kay
http://www.saxonica.com/ 

-----Original Message-----
From: dsk [mailto:dmitrik(_at_)mindspring(_dot_)com] 
Sent: 05 January 2005 04:09
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] for-each and summing based on group


within a for-each there might be various sets of values which 
produce the 
following grid, where val is equal to a number

a  val val val
a  val val val
a  val val val
b  val val val
b  val val val
c  val val val
c  val val val

what is the best way to insert a sum line for the first
column a, one for b, and one for c.

is a nested for each needed? or checking to see if the 
following value is 
not equal to the preceding, then then summing?

thanks,
Dmitri

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.802 / Virus Database: 545 - Release Date: 11/26/2004


--~------------------------------------------------------------------
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>
--~--




--~------------------------------------------------------------------
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>
--~--