Re: [xsl] grouping date ranges with associated sums

Subject: Re: [xsl] grouping date ranges with associated sums
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 30 Nov 2004 15:13:54 GMT
<xsl:template match="Trade">
   <tr>
     <td><xsl:value-of select="TradeId" /></td>
     <td>
       <xsl:text>total:</xsl:text>
       <xsl:call-template name="addSubtotals">

so when you call add Subtotals the current node is Trade

so this 


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

is going to be nothing as Trade doesn't have any Trade children so the
first step in the path has already selected the empty set.

As I said in my original reply for subtotals you need to drop the Trade/
from the beginning.

That's all you need you: don't need any named templates at all you could
replace the entire recursive call by that value-of.


something like:

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

<p>
Total: <xsl:text/>
<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(MinFlowDate,1,2))&lt;  20051129]
   /StepCharge_TTBlack)"/>
</p>

<xsl:for-each select="Trade">
subtotal for <xsl:value-of select="TradeId"/>: <xsl:text/>
<xsl:value-of select="sum(Step
   [concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlowDate,1,2))&gt;= 20041129]
   [concat(substring(MinFlowDate,7),substring(MinFlowDate,4,2),substring(MinFlowDate,1,2))&lt;  20051129]
   /StepCharge_TTBlack)"/>

</xsl:for-each>

</xsl:template>

</xsl:stylesheet>





<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="Ed1.xsl"?>
<Portfilio>
	<Trade>
		<TradeId>ED.TEST</TradeId>	
		<Step>
		   <MinFlowDate>11/11/2004</MinFlowDate>
		   <StepCharge_TTBlack>10</StepCharge_TTBlack>
		</Step>
		<Step>
		   <MinFlowDate>11/11/2005</MinFlowDate>
		   <StepCharge_TTBlack>10</StepCharge_TTBlack>
		</Step>
	</Trade>
	<Trade>
		<TradeId>ED.TESTFX1</TradeId>	
		<Step>
		   <MinFlowDate>11/11/2004</MinFlowDate>
		   <StepCharge_TTBlack>10</StepCharge_TTBlack>
		</Step>
		<Step>
		   <MinFlowDate>11/12/2004</MinFlowDate>
		   <StepCharge_TTBlack>60</StepCharge_TTBlack>
		</Step>
		<Step>
		   <MinFlowDate>11/11/2004</MinFlowDate>
		   <StepCharge_TTBlack>1450</StepCharge_TTBlack>
		</Step>
		<Step>
		   <MinFlowDate>11/11/2009</MinFlowDate>
		   <StepCharge_TTBlack>6320</StepCharge_TTBlack>
		</Step>
	</Trade>	
</Portfilio>



$ saxon total.xml total.xsl
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

      <title>Portfilio</title>
   </head>
   <body>
      <h1>Trade</h1>
      <p>
         Total: 70
      </p>
      subtotal for ED.TEST: 10
      subtotal for ED.TESTFX1: 60
   </body>
</html>

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

Current Thread