Re: [xsl] combine node values

Subject: Re: [xsl] combine node values
From: Edwin Colaco <Edwin.Colaco@xxxxxxx>
Date: Thu, 19 Sep 2002 16:25:17 -0400
Thanks a ton. I was struggling with it for days.
thanks for the links too. very helpful

Edwin

J.Pietschmann wrote:

edwin colaco wrote:

The result I get with this XSL template is Col1        Col2        Col3
aaa        2        1
bbb        2        1
aaa        3        0
bbb        2        1

I would like to get the following result instead
Col1        Col2        Col3
aaa        5        1
bbb        4        2

It seems you hit a standard problem called "grouping", in your
case by the value of EEE/@name. You can inform yourself about
background and solutions in the XSL FAQ
 http://www.dpawson.co.uk/
or at Jeni Tennisons site
 http://www.jenitennison.com/xslt/grouping/index.html

The standard technique is usually called Muenchean Grouping
(after the inventor).
Define a key
  <xsl:key name="eee-name-group" match="EEE" use="@name"/>
This key defines the groups.
In the for-each, check whether the element iss the first of
the group as selected by the key. Use the key again to get all
EEE elements grouped by their name to accumulate the values you
need:

<xsl:for-each select="/AAA/BBB/CCC/DDD/EEE[generate-id()=generate-id(key('eee-name-group',@name)[1])]">

<xsl:variable name="nodes" select="key('eee-name-group',@name)"/>
<xsl:variable name="ct" select="count($nodes/FFF/GGG)"/>
<xsl:variable name="okct" select="count($nodes/FFF/GGG[status='ok'])"/>
<xsl:variable name="failct" select="count($nodes/FFF/GGG[status='fail'])"/>
<xsl:variable name="successRate" select="((($ct)-($failct)) div ($ct))"/>
...



HTH J.Pietschmann


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





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



Current Thread