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

Re: Grouping and Sum problem - XSL 1.0

Subject: Re: Grouping and Sum problem - XSL 1.0
From: Florent Georges <lists@xxxxxxxxxxxx>
Date: Thu, 1 May 2008 16:07:09 +0200 (CEST)
Re:  Grouping and Sum problem - XSL 1.0
Mike Finch wrote:


> Im trying to sum the total royalty for both the row which is
> type RELEASE as well as the following siblings royalties
> which have the same releaseid as well as same order number
> as the preceding RELEASE row.

  I didn't follow this thread closely, so I maybe missed some
info.  But I wonder if you really need grouping.  From the
example you showed up, I would rather use the sibling walking

  You walk over the row one after the other.  Once you detect
the special RELEASE case you switch to another mode that sums
up the royalties.  Once you detect you eat up all the row to
ignore you add the special row to the output tree, with the
royalties sum, and you get back to the regular sibling walk.

  Here is an example that produces the desired output with
your sample input:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

   <xsl:output indent="yes"/>

   <!-- Copy template pattern. -->
   <xsl:template match="@*|node()">
         <xsl:apply-templates select="@*|node()"/>

   <!-- Initiate the sibling walking. -->
   <xsl:template match="document">
         <xsl:apply-templates select="@*|row[1]"/>

   <!-- The actual sibling walking. -->
   <xsl:template match="row">
         <xsl:apply-templates select="@*|node()"/>
      <xsl:apply-templates select="following-sibling::*[1]"/>

   <!-- The special case "eating up" some following siblings. -->
   <xsl:template match="row[type = 'RELEASE']">
          mode="eat-up" select="following-sibling::*[1]">
         <xsl:with-param name="royalty" select="royalty"/>
         <xsl:with-param name="row"     select="."/>

   <!-- Eat up this row or take again the sibling walking? -->
   <xsl:template match="row" mode="eat-up">
      <xsl:param name="royalty"/>
      <xsl:param name="row"/>
      <xsl:variable name="prev-id" select="
         <!-- Continue eating up and summing royalties. -->
         <xsl:when test="
             order = $row/order
                 and ( not($prev-id) or releaseid = $prev-id )">
                mode="eat-up" select="following-sibling::*[1]">
               <xsl:with-param name="royalty" select="
                   $royalty + royalty"/>
               <xsl:with-param name="row"     select="$row"/>
         <!-- Come back on the sibling walking path, after having
              added the previous row to the result tree. -->
            <xsl:element name="{ name($row) }">
               <xsl:apply-templates select="
                  <xsl:value-of select="$royalty"/>
            <xsl:apply-templates select="."/>


  BTW, are you sure you are stuck to XSLT 1.0?  And for good reasons? 
Or is it just "by habit"?



Do You Yahoo!?
En finir avec le spam? Yahoo! Mail vous offre la meilleure protection possible contre les messages non sollicitis 
http://mail.yahoo.fr Yahoo! Mail 

Current Thread


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.
First Name
Last Name
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.