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

RE: Grouping the same set by multiple criteria

Subject: RE: Grouping the same set by multiple criteria
From: Américo Albuquerque <aalbuquerque@xxxxxxxxxxxxxxxx>
Date: Wed, 28 May 2003 19:05:00 +0100
criteria group by
Hi

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Erika Marlow
> Sent: Wednesday, May 28, 2003 3:49 PM
> To: XSL List
> Subject:  Grouping the same set by multiple criteria
> 
> 
> Hello.  I'm trying to group a set of transactions by date 
> then site then payer. Then I have to count how many are in 
> each group, i.e., how many total transactions by date, how 
> many in a date group are from a specific site, and how many 
> in a date/site group are the same payer.  I have used the 
> Muenchian technique to find the unique groups, but I am stuck 
> on how to get the counts for the different groupings.  I can 
> find how many unique dates there are, but not how many 
> transactions are in a given date group.  Is this possible with XSL?
> 

Try this:

 <xsl:key name="G1" match="transaction"
use="original_request/inquiry/@date"/>
 <xsl:key name="G2" match="transaction"
use="concat(original_request/inquiry/@date,'
',original_request/inquiry/site)"/>
 <xsl:key name="G3" match="transaction"
use="concat(original_request/inquiry/@date,'
',original_request/inquiry/site,' ',original_request/inquiry/payer)"/>
 <xsl:key name="payers" match="payer" use="."/>
 
 <xsl:template match="log">
  <xsl:apply-templates
select="transaction[generate-id()=generate-id(key('G1',original_request/
inquiry/@date))]" mode="G1"/>
 </xsl:template>
 
 <xsl:template match="transaction" mode="G1">
  <!-- do whatever with the date, here i'm just displaying the value -->
  <xsl:value-of select="original_request/inquiry/@date"/>
  <xsl:text>&#10;</xsl:text>
  <!-- here i'm applying level2 group -->
  <xsl:apply-templates
select="key('G1',original_request/inquiry/@date)[generate-id()=generate-
id(key('G2',concat(original_request/inquiry/@date,'
',original_request/inquiry/site)))]" mode="G2"/>
  <xsl:text>Total: </xsl:text>
  <!-- the Total is the count of the current group -->
  <xsl:value-of
select="count(key('G1',original_request/inquiry/@date))"/>
  <xsl:text>&#10;</xsl:text>
  <xsl:text>&#10;</xsl:text>
 </xsl:template>
 
 <xsl:template match="transaction" mode="G2">
  <xsl:text>Site: </xsl:text>
  <xsl:value-of select="original_request/inquiry/site"/>
  <xsl:text> transactions: </xsl:text>
  <!-- counting transactions of the current group -->
  <xsl:value-of
select="count(key('G2',concat(original_request/inquiry/@date,'
',original_request/inquiry/site)))"/>
  <xsl:text>&#10;</xsl:text>
  <!--
  I can't apply as before because you want all payers displayed,
  so i use the payers key to group by unique payers and pass the current
date and site as parameters.
  -->
  <xsl:apply-templates
select="../transaction/original_request/inquiry/payer[generate-id()=gene
rate-id(key('payers',.))]" mode="G3">
   <xsl:with-param name="date" select="original_request/inquiry/@date"/>
   <xsl:with-param name="site" select="original_request/inquiry/site"/>
  </xsl:apply-templates>
 </xsl:template>
 
 <xsl:template match="payer" mode="G3">
  <xsl:param name="date"/>
  <xsl:param name="site"/>
  <xsl:text>  Payer: </xsl:text>
  <xsl:value-of select="."/>
  <xsl:text> transactions: </xsl:text>
  <!-- use the parameters date and site in the G3 key to get the correct
values for the count -->
  <xsl:value-of select="count(key('G3',concat($date,' ',$site,'
',.)))"/>
  <xsl:text>&#10;</xsl:text>
 </xsl:template>

Hope this helps you.




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.