Subject: RE: [xsl] Multiple groupings From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx> Date: Tue, 27 Apr 2004 09:46:16 -0400 |
Ken, I am outputting this data to html. When I use this XSL: <xsl:template match="ArrayOfAccountLineItem"> <!-- CAPTURE ALL AccountLineItem NODES IN A VARIABLE --> <xsl:variable name="items" select="/ArrayOfAccountLineItem/AccountLineItem"/> <!-- LOOP THROUGH ALL AccountLineItems --> <xsl:for-each select="$items"> <!-- IF THE CONTEXT NODE IS THE FIRST NODE IN THE TREE WITH THE CONTEXT PaymentType --> <xsl:if test="generate-id(.) = generate-id($items[PaymentType=current()/PaymentType])"> <!-- CAPTURE ALL NODES WITH A MATCHING PaymentType --> <xsl:variable name="payments" select="$items[PaymentType=current()/PaymentType]"/> <xsl:value-of select="PaymentType"/><br/> <!-- LOOP THROUGH ALL NODES WITH MATCHING PaymentType --> <xsl:for-each select="$payments"> <!-- IF THE CONTEXT NODE IS THE FIRST NODE IN THE TREE WITH THE CONTEXT CityName --> <xsl:if test="generate-id(.) = generate-id($payments[CityName=current()/CityName])"> <xsl:value-of select="CityName"/><br/> <!-- LOOP THROUGH ALL NODES WITH MATCHING CityName --> <xsl:for-each select="$payments[CityName=current()/CityName]"> <xsl:apply-templates select="."> <xsl:with-param name="count" select="position()"/> </xsl:apply-templates> </xsl:for-each> </xsl:if> </xsl:for-each> </xsl:if> </xsl:for-each> </xsl:template> I am getting all of the PaymentType and CityName at the very top of the report. Then I get all of the records sequentially below that. How can I break the record listing and subtitle each section? It worked fine in the text version. For totaling, should I just use keys? Thanks again, Kenny Akridge -----Original Message----- From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx] Sent: Tuesday, April 27, 2004 7:03 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Multiple groupings At 2004-04-27 00:13 -0400, Kenny Akridge wrote: >I basically have XML that has a PaymentType, City, Date and ID. I >need to group all records by PaymentType then by City. I find multi-level grouping is most easily solved using variable-based grouping. >I need to total by city and by Payment type. I don't see any numbers to be totalled in your XML. >Any thoughts on the best way to tackle this? Below is a working example with your data. Note how I use variables to capture the subset of the document in which I need to do grouping, so that I don't always have to deal with document-wide scope. I hope this helps. ...................... Ken 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:output method="text"/> <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 t:\ftemp>rem Done! -- Public courses: Spring 2004 world tour of hands-on XSL instruction Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO Hong Kong May 17-21; Bremen Germany May 24-28; Helsinki June 14-18 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, Kenny Akridge | Thread | RE: [xsl] Multiple groupings, G. Ken Holman |
RE: [xsl] Getting position while ig, Andrew Welch | Date | [xsl] ANN: XSLT 2.0 and XPath 2.0 b, Michael Kay |
Month |