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

Re: combine node values

Subject: Re: combine node values
From: Edwin Colaco <Edwin.Colaco@xxxxxxx>
Date: Thu, 19 Sep 2002 16:25:17 -0400
xslt combine nodes
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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-2013 All Rights Reserved.