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

Grouping question

Subject: Grouping question
From: "Nishma Jain" <njain@xxxxxxxxxxxx>
Date: Thu, 12 Aug 2004 12:41:44 -0600
xsl grouping
Hi,

I'm having a grouping issue. In my case root tag is "Statements" and
under Statements I can have multiple Statement tags. I'm using muenchian
method for grouping but I need to group within a Statement tag as oppose
to the whole xsl doc. Now within each Statement I have to calculate
month totals. Since all the months and dates are dynamic so I'm using
grouping to get a set of amounts according to the month and year. As you
can see in the output, amounts from the 2nd statement node are showing
up in the first statement since key is getting applied to the whole xml
doc. I need to restrict it to the current statement node only. Is there
any way to do it? How can I specify current id or any other attribute of
the statement in the key or any other idea???

Hope I made myself clear. Attached are my test xml and xsl scripts.

Thanks in advance,
Nishma

My output...

Statement:1
	Name:AAA
    	Date 2004-07-09 amount: 1.00
    	Date 2004-07-10 amount: 2.00
    	Date 2004-07-08 amount: 1.00
    	Date 2004-07-19 amount: 3.00
     MONTH TOTAL : 7.00
    	Date 2004-08-09 amount: 3.00
    	Date 2004-08-10 amount: 4.00
    	Date 2004-08-11 amount: 5.00
    	Date 2004-08-22 amount: 2.00
     MONTH TOTAL : 14.00
Statement:2
	Name:BBB
    	Date 2004-09-10 amount: 4.00
     MONTH TOTAL : 4.00

  Required output .....

Statement:1
	Name:AAA
    	Date 2004-07-09 amount: 1.00
    	Date 2004-07-10 amount: 2.00
     MONTH TOTAL : 3.00
    	Date 2004-08-09 amount: 3.00
    	Date 2004-08-10 amount: 4.00
    	Date 2004-08-11 amount: 5.00
     MONTH TOTAL : 12.00
Statement:2
	Name:BBB
		Date 2004-07-08 amount: 1.00
    	Date 2004-07-19 amount: 3.00
     MONTH TOTAL : 4.00
     	Date 2004-08-22 amount: 2.00
     MONTH TOTAL : 2.00
    	Date 2004-09-10 amount: 4.00
     MONTH TOTAL : 4.00

My xml:

<Statements>
 	<Statement number="1" total="15">
 		<Property name="AAA">
 			<Line pDate="2004-07-09" amount="1.00"/>
 			<Line pDate="2004-07-10" amount="2.00"/>
 			<Line pDate="2004-08-09" amount="3.00"/>
 			<Line pDate="2004-08-10" amount="4.00"/>
 			<Line pDate="2004-08-11" amount="5.00"/>
  		</Property>
 	</Statement>
 	<Statement number="2" total="10">
 		<Property name="BBB">
 			<Line pDate="2004-07-08" amount="1.00"/>
 			<Line pDate="2004-08-22" amount="2.00"/>
 			<Line pDate="2004-07-19" amount="3.00"/>
 			<Line pDate="2004-09-10" amount="4.00"/>
  		</Property>
 	</Statement>
</Statements>

My xsl:

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="line-date" match="Statements/Statement/Property/Line"
use="concat(substring(@pDate, 6, 2),'-', substring(@pDate, 1, 4))" />

<xsl:template match="Statements">
		<xsl:apply-templates  select='Statement'/>
</xsl:template>

<xsl:template match="Statement">
Statement:<xsl:value-of select='@number'/>
		<xsl:apply-templates select='Property'/>

</xsl:template>

<xsl:template match="Property">
	Name:<xsl:value-of select='@name'/>
	<xsl:apply-templates select="Line[generate-id(.) =
generate-id(key('line-date', concat(substring(@pDate, 6, 2),'-',
substring(@pDate, 1, 4)) )[1]) ]"/>
</xsl:template>

<xsl:template match="Line">
	<xsl:for-each select="key('line-date', concat(substring(@pDate,
6, 2),'-', substring(@pDate, 1, 4)))">
    	Date <xsl:value-of select='@pDate'/> amount: <xsl:value-of
select='format-number(@amount, "#,###,##0.00")'/>
    </xsl:for-each>
     <!--Month totals.. -->MONTH TOTAL : <xsl:value-of
select="format-number(sum(key('line-date',concat(substring(@pDate, 6,
2),'-', substring(@pDate, 1, 4)))/@amount),'#,###,##0.00')"/>
</xsl:template>

</xsl:stylesheet>

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.