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

Re: [XSL] Grouping and Sum problem - XSL 1.0

Subject: Re: [XSL] Grouping and Sum problem - XSL 1.0
From: Michael Ludwig <mlu@xxxxxxxxxxxxx>
Date: Wed, 30 Apr 2008 13:37:06 +0200
Re:  [XSL] Grouping and Sum problem - XSL 1.0
Mike Finch [Wasabeat] schrieb:
Yes, im trying to do an xsl:copy-of for the results but I cannot
get the sum's to add up when grouping the rows.  Im trying to sum
the grouped row's <royalty> <mechanicals> <taxes> <expenses>
elements however I can only get the sums to add up for the first
following sibling.  I need to add sums for all following siblings
which have the same <releaseid> and <order> as the row with they
type='RELEASE'

Okay, and I'm guessing that you only want to do this for row[type = 'RELEASE'].

Below is the XSL properly indented. Sorry about that.

Indentation wasn't the main point. It's just that minimal examples, stripped of everything that is not essential to the problem, are a lot easier to grasp.

Anyway, try this:

<xsl:transform version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Requirement: Im having problems getting the sum for the royalty,
  mechanicals, taxes and expenses elements of my grouping to sum correctly.
  [...] I need to add sums for all following siblings which have the same
  <releaseid> and <order> as the row with the type='RELEASE'. -->
  <xsl:output indent="yes"/>
  <xsl:template match="row[ type = 'RELEASE' ]">
    <xsl:copy>
      <xsl:apply-templates/>
      <royalty-sum>
        <xsl:value-of select="
          sum(
            following-sibling::row[
              releaseid = current()/releaseid and
              order     = current()/order
            ]/royalty
          )"/>
      </royalty-sum>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="@*|node()"><!-- identity template -->
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:transform>

Michael Ludwig

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.