xsl-list
[Top] [All Lists]

Re: Multiple groupings

2004-04-27 07:24:32
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(_at_)akridgefamily(_dot_)com> 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.



--+------------------------------------------------------------------
XSL-List info and archive: 
http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to:
http://lists.mulberrytech.com/xsl-list/
or e-mail:
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--




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


<Prev in Thread] Current Thread [Next in Thread>