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

Re: Multiple groupings

Subject: Re: Multiple groupings
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Tue, 27 Apr 2004 07:24:32 -0700 (PDT)
xsl for each multiple
Here is another solution -

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xalan="http://xml.apache.org/xalan"
exclude-result-prefixes="xalan">
<xsl:output method="text" version="1.0"
encoding="UTF-8" indent="yes"/>
	
<xsl:key name="by-payment-type"
match="AccountLineItem" use="PaymentType"/>
<xsl:key name="by-city" match="AccountLineItem"
use="CityName"/>
	
<xsl:template match="ArrayOfAccountLineItems">
  <xsl:for-each select="AccountLineItem">
   <xsl:if test="generate-id(.) =
generate-id(key('by-payment-type', PaymentType)[1])">
      PaymentType: <xsl:value-of
select="PaymentType"/>
	<xsl:variable name="rtf">
	  <xsl:for-each select="key('by-payment-type',
PaymentType)">						    <AccountLineItem>
	     <ID>
		<xsl:value-of select="ID"/>
	     </ID>
	     <SettleDate>
	        <xsl:value-of select="SettleDate"/>
	     </SettleDate>
	     <CityName>
		<xsl:value-of select="CityName"/>
	     </CityName>
	    </AccountLineItem>
	  </xsl:for-each>
	</xsl:variable>
				
	<xsl:for-each
select="xalan:nodeset($rtf)/AccountLineItem">
	  <xsl:if test="generate-id(.) =
generate-id(key('by-city', CityName)[1])">
	     City: <xsl:value-of select="CityName"/>
	      <xsl:for-each select="key('by-city',
CityName)">
	        ID: <xsl:value-of select="ID"/>
                SettleDate: <xsl:value-of
select="SettleDate"/>
              </xsl:for-each> 
              Total : <xsl:value-of
select="count(key('by-city', CityName))"/>   
	  </xsl:if>
	</xsl:for-each>
				
	Total : <xsl:value-of
select="count(key('by-payment-type', PaymentType))"/> 
 
    </xsl:if>
  </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Regards,
Mukul


--- Kenny Akridge <kenny@xxxxxxxxxxxxxxxxx> wrote:
> I've looked at the FAQs, but have had a hard time
> making any certain methods
> work.  I basically have XML that has a PaymentType,
> City, Date and ID.  I
> need to group all records by PaymentType then by
> City.  I need to total by
> city and by Payment type.  Here is some sample XML.
> 
> <?xml version="1.0" encoding="UTF-16"?>
> <ArrayOfAccountLineItems>
> 	<AccountLineItem>
> 		<ID>12993</ID>
> 		<PaymentType>Credit Card</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:46.6230000-04:00</SettleDate>
> 		<CityName>Las Vegas</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12992</ID>
> 		<PaymentType>Cash</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:46.6230000-04:00</SettleDate>
> 		<CityName>New York</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12963</ID>
> 		<PaymentType>Check</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:51.3100000-04:00</SettleDate>
> 		<CityName>Orlando</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12962</ID>
> 		<PaymentType>Check</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:51.3100000-04:00</SettleDate>
> 		<CityName>New York</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12969</ID>
> 		<PaymentType>Credit Card</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:51.4830000-04:00</SettleDate>
> 		<CityName>Las Vegas</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12968</ID>
> 		<PaymentType>Voucher</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:51.4830000-04:00</SettleDate>
> 		<CityName>Orlando</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12975</ID>
> 		<PaymentType>Check</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:51.6400000-04:00</SettleDate>
> 		<CityName>Las Vegas</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12974</ID>
> 		<PaymentType>Check</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:51.6400000-04:00</SettleDate>
> 		<CityName>Orlando</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12981</ID>
> 		<PaymentType>Voucher</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:51.8100000-04:00</SettleDate>
> 		<CityName>New York</CityName>
> 	</AccountLineItem>
> 	<AccountLineItem>
> 		<ID>12980</ID>
> 		<PaymentType>Cash</PaymentType>
> 	
>
<SettleDate>2004-04-14T22:57:51.8100000-04:00</SettleDate>
> 		<CityName>Orlando</CityName>
> 	</AccountLineItem>
> </ArrayOfAccountLineItems>
> 
> II have been trying the for-each PaymentType[not(. =
> preceding::PaymentType)] approach.
> 
> Any thoughts on the best way to tackle this?
> 
> Thanks.
> 



	
		
__________________________________
Do you Yahoo!?
Win a $20,000 Career Makeover at Yahoo! HotJobs  
http://hotjobs.sweepstakes.yahoo.com/careermakeover 

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.