RE: [xsl] grouping date ranges with associated sums

Subject: RE: [xsl] grouping date ranges with associated sums
From: "dsk" <dmitrik@xxxxxxxxxxxxxx>
Date: Mon, 29 Nov 2004 21:43:51 -0500
where can this code fit into the below xsl code, so that
one row can be used to display sums within 3 different yearly groups?

<xsl:value-of select="sum(Trade/Step

[concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlo
wDate,1,2))&gt;= 20041129]

[concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlo
wDate,1,2))&lt;  20051129]
   /StepCharge_TTBlack)"/>


thanks,
dk

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   version="1.0">

<xsl:output method="html" indent="yes" />

<xsl:template match="/">
   <html>
     <head>
       <title>Portfilio</title>
     </head>
     <body>
       <h1>Trade</h1>
       <xsl:apply-templates />
	   </body>
   </html>
</xsl:template>

<xsl:template match="Portfilio">
   <table>
     <tbody>
       <xsl:apply-templates select="Trade" />
     </tbody>
   </table>
</xsl:template>

<xsl:template match="Trade">
   <tr>
     <td><xsl:value-of select="TradeId" /></td>
     <td>
       <xsl:text>total:</xsl:text>
       <xsl:call-template name="addSubtotals">
         <xsl:with-param name="Steps" select="Step" />
       </xsl:call-template>
	<xsl:call-template name="addSubtotals1">
         <xsl:with-param name="Steps" select="Step" />
       </xsl:call-template>
     </td>
   </tr>
</xsl:template>

<xsl:template name="addSubtotals">
   <xsl:param name="Steps" />
   <xsl:variable name="Step1" select="$Steps[1]" />
   <xsl:variable name="RemainingItems" select="$Steps[position() &gt; 1]" />
   <xsl:variable name="subtotal" select="$Step1/StepCharge_TTBlack" />
   <xsl:choose>
     <xsl:when test="$RemainingItems">
       <xsl:variable name="subtotals">
         <xsl:call-template name="addSubtotals">
           <xsl:with-param name="Steps" select="$RemainingItems" />
         </xsl:call-template>
       </xsl:variable>

	<br></br>

	<xsl:value-of
select="sum(Trade/Step[concat(substring(MinFlowDate,7),substring(MinFlowDate
,4,2),substring(MinFlowDate,1,2))&gt;=20041129]

[concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlo
wDate,1,2))&lt;20051129]/StepCharge_TTBlack)"/>
	<xsl:value-of select="$subtotal + $subtotals" />
<!--
	<xsl:choose>
        <xsl:when test="number($MinFlowDate) >= number($currentdate) and
number($MinFlowDate) &lt;= number($datebucket1)">

      	1)<xsl:value-of select="$subtotal + $subtotals" />

        </xsl:when>
        <xsl:when test="number($MinFlowDate) >= number($datebucket1) and
number($MinFlowDate) &lt;= number($datebucket2)">
           2)<xsl:value-of select="$subtotal + $subtotals" />
        </xsl:when>
	 <xsl:when test="number($MinFlowDate) >= number($datebucket2) and
number($MinFlowDate) &lt;= number($datebucket3)">
           3)<xsl:value-of select="$subtotal + $subtotals" />
        </xsl:when>
        <xsl:otherwise>
        </xsl:otherwise>
      </xsl:choose> -->




     </xsl:when>
     <xsl:otherwise>
       <xsl:value-of select="$subtotal" />
	<xsl:value-of
select="sum(Trade/Step[concat(substring(MinFlowDate,7),substring(MinFlowDate
,4,2),substring(MinFlowDate,1,2))&gt;=20041129]

[concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlo
wDate,1,2))&lt;20051129]/StepCharge_TTBlack)"/>


     </xsl:otherwise>
   </xsl:choose>
</xsl:template>

<xsl:template name="addSubtotals1">
   <xsl:param name="Steps" />
   <xsl:variable name="Step1" select="$Steps[1]" />
   <xsl:variable name="RemainingItems" select="$Steps[position() &gt; 1]" />
   <xsl:variable name="subtotal" select="$Step1/StepCharge_TTBlack" />
   <xsl:choose>
     <xsl:when test="$RemainingItems">
       <xsl:variable name="subtotals">
         <xsl:call-template name="addSubtotals1">
           <xsl:with-param name="Steps" select="$RemainingItems" />
         </xsl:call-template>
       </xsl:variable>
		<xsl:value-of
select="sum(Trade/Step[concat(substring(MinFlowDate,7),substring(MinFlowDate
,4,2),substring(MinFlowDate,1,2))&gt;=20051129]

[concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlo
wDate,1,2))&lt;20061129]/StepCharge_TTBlack)"/>


       <!--<xsl:value-of select="$subtotal + $subtotals" />-->
     </xsl:when>
     <xsl:otherwise>
      <!-- <xsl:value-of select="$subtotal" />-->
	<xsl:value-of
select="sum(Trade/Step[concat(substring(MinFlowDate,7),substring(MinFlowDate
,4,2),substring(MinFlowDate,1,2))&gt;=20051129]

[concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlo
wDate,1,2))&lt;20061129]/StepCharge_TTBlack)"/>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>






</xsl:stylesheet>

-----Original Message-----
From: David Carlisle [mailto:davidc@xxxxxxxxx]
Sent: Monday, November 29, 2004 12:26 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] grouping date ranges with associated sums


>
> example from today until 1 year - any MinFlowDate which falls within that
> range will be summed

assuming you have dd/mm/yyyy then:

<xsl:value-of select="sum(Trade/Step

[concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlo
wDate,1,2))&gt;= 20041129]

[concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlo
wDate,1,2))&lt;  20051129]
   /StepCharge_TTBlack)"/>

does the total, the same without the Trade/ at the beginning would give
the sum for each trade separately (if the Trade elements were the
current node in that case)

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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

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

Current Thread