|
Subject: Re: [xsl] Multiple groupings From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 27 Apr 2004 07:02:30 -0400 |
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.
Any thoughts on the best way to tackle this?
t:\ftemp>type akridge.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
t:\ftemp>type akridge.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:variable name="items"
select="/ArrayOfAccountLineItems/AccountLineItem"/>
<xsl:for-each select="$items">
<xsl:if test="generate-id(.)=
generate-id($items[PaymentType=current()/PaymentType])">
<xsl:variable name="payments"
select="$items[PaymentType=current()/PaymentType]"/>
<xsl:text/>Payments for '<xsl:value-of select="PaymentType"/>':
<xsl:text/>
<xsl:for-each select="$payments">
<xsl:if test="generate-id(.)=
generate-id($payments[CityName=current()/CityName])">
<xsl:text/> In city '<xsl:value-of select="CityName"/>:
<xsl:text/>
<xsl:for-each select="$payments[CityName=current()/CityName]">
<xsl:value-of select="concat(' ID:',ID,' Date:',SettleDate)"/>
<xsl:text>
</xsl:text>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>
</xsl:template></xsl:stylesheet>
t:\ftemp>saxon akridge.xml akridge.xsl
Payments for 'Credit Card':
In city 'Las Vegas:
ID:12993 Date:2004-04-14T22:57:46.6230000-04:00
ID:12969 Date:2004-04-14T22:57:51.4830000-04:00
Payments for 'Cash':
In city 'New York:
ID:12992 Date:2004-04-14T22:57:46.6230000-04:00
In city 'Orlando:
ID:12980 Date:2004-04-14T22:57:51.8100000-04:00
Payments for 'Check':
In city 'Orlando:
ID:12963 Date:2004-04-14T22:57:51.3100000-04:00
ID:12974 Date:2004-04-14T22:57:51.6400000-04:00
In city 'New York:
ID:12962 Date:2004-04-14T22:57:51.3100000-04:00
In city 'Las Vegas:
ID:12975 Date:2004-04-14T22:57:51.6400000-04:00
Payments for 'Voucher':
In city 'Orlando:
ID:12968 Date:2004-04-14T22:57:51.4830000-04:00
In city 'New York:
ID:12981 Date:2004-04-14T22:57:51.8100000-04:00-- Public courses: Spring 2004 world tour of hands-on XSL instruction Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO
World-wide on-site corporate, govt. & user group XML/XSL training. G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Multiple groupings, Jarno.Elovirta | Thread | RE: [xsl] Multiple groupings, Kenny Akridge |
| Re: AW: AW: [xsl] tomcat web server, Emmanuil Batsis (Man | Date | AW: AW: AW: [xsl] tomcat web server, Nikolas Nehmer |
| Month |