RE: [xsl] Multiple groupings

Subject: RE: [xsl] Multiple groupings
From: "Kenny Akridge" <kenny@xxxxxxxxxxxxxxxxx>
Date: Tue, 27 Apr 2004 10:09:44 -0400
You know it figures, I realized that right after I sent the email.  
Thanks a lot for your straightforward, user friendly advice.


-----Original Message-----
From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx] 
Sent: Tuesday, April 27, 2004 10:03 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Multiple groupings

At 2004-04-27 09:46 -0400, Kenny Akridge wrote:
>I am outputting this data to html.  When I use this XSL:
>...
>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.

On the surface it sounds perhaps like a table problem ... when HTML renders 
tables, if you have information not properly wrapped in the table I think 
it gets shown in advance of the table.

>How can I
>break the record listing and subtitle each section?  It worked fine in the
>text version.

By fixing your HTML ... if it works as you wish for the text version, then 
you don't have a problem traversing the XML as you desire, you have a 
problem wrapping the information in your target vocabulary (in this case, 
HTML).

>For totaling, should I just use keys?

No, because you'll have the same problem because using keys only works with 
document-wide scope ... that's the awkwardness when it comes to doing 
subgrouping as subsgrouping cannot easily work with document-wide 
scope.  Just use the variables as they are created.

An example below includes amounts and totals.

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>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12992</ID>
                 <PaymentType>Cash</PaymentType>
                 <SettleDate>2004-04-14T22:57:46.6230000-04:00</SettleDate>
                 <CityName>New York</CityName>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12963</ID>
                 <PaymentType>Check</PaymentType>
                 <SettleDate>2004-04-14T22:57:51.3100000-04:00</SettleDate>
                 <CityName>Orlando</CityName>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12962</ID>
                 <PaymentType>Check</PaymentType>
                 <SettleDate>2004-04-14T22:57:51.3100000-04:00</SettleDate>
                 <CityName>New York</CityName>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12969</ID>
                 <PaymentType>Credit Card</PaymentType>
                 <SettleDate>2004-04-14T22:57:51.4830000-04:00</SettleDate>
                 <CityName>Las Vegas</CityName>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12968</ID>
                 <PaymentType>Voucher</PaymentType>
                 <SettleDate>2004-04-14T22:57:51.4830000-04:00</SettleDate>
                 <CityName>Orlando</CityName>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12975</ID>
                 <PaymentType>Check</PaymentType>
                 <SettleDate>2004-04-14T22:57:51.6400000-04:00</SettleDate>
                 <CityName>Las Vegas</CityName>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12974</ID>
                 <PaymentType>Check</PaymentType>
                 <SettleDate>2004-04-14T22:57:51.6400000-04:00</SettleDate>
                 <CityName>Orlando</CityName>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12981</ID>
                 <PaymentType>Voucher</PaymentType>
                 <SettleDate>2004-04-14T22:57:51.8100000-04:00</SettleDate>
                 <CityName>New York</CityName>
                 <Amount>123</Amount>
         </AccountLineItem>
         <AccountLineItem>
                 <ID>12980</ID>
                 <PaymentType>Cash</PaymentType>
                 <SettleDate>2004-04-14T22:57:51.8100000-04:00</SettleDate>
                 <CityName>Orlando</CityName>
                 <Amount>123</Amount>
         </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:text/>    Total for <xsl:value-of select="CityName"/>
           <xsl:text>: </xsl:text>
           <xsl:value-of
 
select="sum($payments[CityName=current()/CityName]/Amount)"/>
           <xsl:text>
</xsl:text>
         </xsl:if>
       </xsl:for-each>
       <xsl:text/>  Total for <xsl:value-of select="PaymentType"/>
       <xsl:text>: </xsl:text>
       <xsl:value-of
 
select="sum($payments[PaymentType=current()/PaymentType]/Amount)"/>
       <xsl:text>
</xsl:text>
     </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
     Total for Las Vegas: 246
   Total for Credit Card: 246
Payments for 'Cash':
   In city 'New York':
     ID:12992 Date:2004-04-14T22:57:46.6230000-04:00
     Total for New York: 123
   In city 'Orlando':
     ID:12980 Date:2004-04-14T22:57:51.8100000-04:00
     Total for Orlando: 123
   Total for Cash: 246
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
     Total for Orlando: 246
   In city 'New York':
     ID:12962 Date:2004-04-14T22:57:51.3100000-04:00
     Total for New York: 123
   In city 'Las Vegas':
     ID:12975 Date:2004-04-14T22:57:51.6400000-04:00
     Total for Las Vegas: 123
   Total for Check: 492
Payments for 'Voucher':
   In city 'Orlando':
     ID:12968 Date:2004-04-14T22:57:51.4830000-04:00
     Total for Orlando: 123
   In city 'New York':
     ID:12981 Date:2004-04-14T22:57:51.8100000-04:00
     Total for New York: 123
   Total for Voucher: 246

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