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

Re: Grouping and Key Problem

Subject: Re: Grouping and Key Problem
From: Mukul Gandhi <mukulgandhi2003@xxxxxxxxxxx>
Date: Fri, 9 Apr 2004 13:37:12 +0100 (BST)
newdataset
Hi James,
  I am not in a position to modify your XSL. But I can
suggest a piece of code. You need to define keys as
below, to do "grouping at two levels". 

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0"
encoding="UTF-8" indent="yes"/>
	
<xsl:key name="kDate" match="Table" use="date"/>
<xsl:key name="kCustomer" match="Table"
use="concat(date,'+',CustomerName)"/>
	
<xsl:template match="/NewDataSet">
  <xsl:for-each select="Table">
     <xsl:if test="generate-id(.) =
generate-id(key('kDate', date)[1])">	
       <xsl:value-of select="date" />
       <xsl:for-each select="key('kDate', date)">
	  <xsl:if test="generate-id(.) =
generate-id(key('kCustomer',
concat(date,'+',CustomerName))[1])">					<xsl:value-of
select="CustomerName"/>
	  </xsl:if>
       </xsl:for-each>
     </xsl:if>
  </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

 --- James Hunt <jamesanthonyhunt@xxxxxxxxx> wrote: >
I'm having problems with grouping and the use of
> keys
> can anyone tell me what I'm doing wrong here. I have
> two records of John on the 12/13/2001 They shouldn't
> display separated. How can I make this tranform into
> something like this:
> 
> 12/13/2001
> John
>   Water Plant
>   Mail
> 12/13/2001
> Jimmy
>   Mail
> 
> Right now it is giving this:
> 
> 12/13/2001
> John
>   Water Plant
>   Mail
> John
>   Water Plant
>   Mail
> 12/13/2001
> Jimmy
>   Mail
> 
> XML File
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <NewDataSet>
> 	<Table>
> 		<mymonth>12</mymonth>
> 		<myday>13</myday>
> 		<myyear>2001</myyear>
> 		<CustomerName>John</CustomerName>
> 		<date>12/13/2001</date>
> 		<TimesPerDay>4</TimesPerDay>
> 		<ServiceName>Water Plant</ServiceName>
> 	</Table>
> 	<Table>
> 		<mymonth>12</mymonth>
> 		<myday>13</myday>
> 		<myyear>2001</myyear>
> 		<CustomerName>John</CustomerName>
> 		<date>12/13/2001</date>
> 		<TimesPerDay>5</TimesPerDay>
> 		<ServiceName>Mail</ServiceName>
> 	</Table>
> 	<Table>
> 		<mymonth>12</mymonth>
> 		<myday>13</myday>
> 		<myyear>2001</myyear>
> 		<CustomerName>Jimmy</CustomerName>
> 		<date>12/13/2001</date>
> 		<TimesPerDay>5</TimesPerDay>
> 		<ServiceName>Mail</ServiceName>
> 	</Table>
> 	<Table>
> 		<mymonth>12</mymonth>
> 		<myday>14</myday>
> 		<myyear>2001</myyear>
> 		<CustomerName>Jimmy</CustomerName>
> 		<date>12/14/2001</date>
> 		<TimesPerDay>5</TimesPerDay>
> 		<ServiceName>Mail</ServiceName>
> 	</Table>
> </NewDataSet>
> 
> 
> 
> 
> XSLT
> 
> 
> 
> <?xml version="1.0" encoding="UTF-8"?>
> 
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> 	<xsl:output method="html" version="1.0"
> indent="yes"/>
> 	<xsl:key name="kCustomer" match="Table"
> use="CustomerName"/>
> 	<xsl:key name="kDate" match="Table" use="date"/>
> 
> 	<xsl:template match="NewDataSet">
> 		<head>
> 			<title>Employee's Week Schedule</title>
> 			<link href="../css/reports.css" type="text/css"
> rel="stylesheet" />
> 		</head>	
> 
> 		<table border="0" cellpadding="4"
> style="border-collapse:collapse;" width="100%">
> 			<tr>
> 				<td colspan="1">
> 					<b>Customer Name</b>
> 				</td>
> 				<td colspan="1">
> 					<b>Service Name</b>
> 				</td>	
> 				<td colspan="2">
> 					<b>Times Per Day</b>
> 				</td>							
> 			</tr>					
> 				<xsl:apply-templates select="Table[generate-id()
> =
> generate-id(key('kDate', date))]" mode="row1"/>					
> 
> 		</table >
> 	</xsl:template>	
> 
> 
> 	<xsl:template match="Table" mode="row1">	
> 		<tr>
> 			<td colspan="4">		
> 				<div style="background-color:red"><xsl:value-of
> select="date"/></div>
> 				<xsl:apply-templates
> select="parent::NewDataSet/Table[date =
> current()/date][CustomerName = key('kCustomer',
> CustomerName)/CustomerName]" mode="row2"/>
> 			</td>
> 		</tr>
> 
> 	</xsl:template>
> 
> 	<xsl:template match="Table" mode="row2">
> 		<tr>
> 			<td colspan="4">			
> 				<hr/>
> 				<xsl:value-of select="CustomerName"/>
>   			      <xsl:apply-templates
> select="parent::NewDataSet/Table[date =
> current()/date][CustomerName =
> current()/CustomerName][ServiceName]" mode="row3"/>
> 			</td>			
> 		</tr>
> 	</xsl:template>
> 	
> 	<xsl:template match="Table" mode="row3">
> 		<tr>
> 			<td />
> 			<td colspan="1">			
> 				<xsl:value-of select="ServiceName"/>
> 			</td>
> 			<td colspan="2">			
> 				<xsl:value-of select="TimesPerDay"/>
> 			</td>						
> 		</tr>		
> 	</xsl:template>
> 	
> </xsl:stylesheet>
> 
> 
> =====
> Home: (513) 661 - 8007 
> Cell: (513) 884 - 4868 
> Email: jamesanthonyhunt@xxxxxxxxx
> 
> __________________________________
> Do you Yahoo!?
> Yahoo! Small Business $15K Web Design Giveaway 
> http://promotions.yahoo.com/design_giveaway/
>  

________________________________________________________________________
Yahoo! India Matrimony: Find your partner online. http://yahoo.shaadi.com/india-matrimony/

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.