Altova Mailing List Archives


Re: [xsl] Grouping and Key Problem

From: Mukul Gandhi <mukulgandhi2003@----------->
To:
Date: 4/10/2004 2:14:00 AM
Hi James,
  This should be ok. I ommited a xsl:for-each loop in
my previous answer.

<?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"
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">
<html>
  <table border="">
    <xsl:for-each select="Table">
	<xsl:if test="generate-id(.) =
generate-id(key('kDate', date)[1])">
	  <tr>
	    <td colspan="4">
	      <xsl:value-of select="date"/>
	    </td>
	  </tr>
	<xsl:for-each select="key('kDate', date)">
	  <xsl:if test="generate-id(.) =
generate-id(key('kCustomer',concat(date,'+',CustomerName))[1])">
	   <xsl:for-each select="key('kCustomer',
concat(date,'+',CustomerName))">
	     <xsl:if test="position() = 1">
		<tr>
		  <td/>
	 	  <td>
		   <xsl:value-of select="CustomerName"/>
		  </td>
		  <td>
		    <xsl:value-of select="ServiceName"/>
		  </td>
		  <td>
		    <xsl:value-of select="TimesPerDay"/>
		  </td>
	   </tr>
    </xsl:if>
    <xsl:if test="not(position() = 1)">
      <tr>
	 <td colspan="2"/>
	   <td>
	     <xsl:value-of select="ServiceName"/>
	   </td>
	   <td>
	     <xsl:value-of select="TimesPerDay"/>
	   </td>
     </tr>
   </xsl:if>
</xsl:for-each>
</xsl:if>
</xsl:for-each>					</xsl:if>
</xsl:for-each>
</table>
</html>

</xsl:template>
</xsl:stylesheet>

Regards,
Mukul

 --- James Hunt <jamesanthonyhunt@xxxxxxxxx> wrote: >
Hi Mukul,
> 
> Thanks for all your help, but I'm only getting the
> first customer from each date. 
> 
> Current Output:
> 
> 12/13/2001 
>  John  Water Plant 4 
>        Mail        5 
> 12/14/2001 
>  Jimmy Mail        5 
> 
> What I need:
> 12/13/2001 
>  John Water Plant 4 
>  Mail             5 
>  Jimmy      Mail  5 
> 12/14/2001 
>  Jimmy      Mail  5 
> 
> Can you tell me what I need to do?
> 
> Thanks,
> James
> 
> --- Mukul Gandhi <mukulgandhi2003@xxxxxxxxxxx>
> wrote:
> > Hi James,
> >   I have written the logic specific to your
> > requirement. Hope its useful.
> > 
> > <?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"
> > 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">
> >   <html>
> >     <table border="1">
> >       <xsl:for-each select="Table">
> > 	<xsl:if test="generate-id(.) =
> > generate-id(key('kDate', date)[1])">
> > 	<tr>
> > 	  <td colspan="4">
> > 	    <xsl:value-of select="date"/>
> > 	  </td>
> > 	</tr>
> > 	<xsl:for-each select="key('kDate', date)">
> > 	   <xsl:if test="generate-id(.) =
> >
>
generate-id(key('kCustomer',concat(date,'+',CustomerName))[1])">
> > 	     <xsl:if test="position() = 1">
> > 		<tr>
> > 		  <td/>
> > 		  <td>
> > 		   <xsl:value-of select="CustomerName"/>
> > 		  </td>
> > 		  <td>
> > 		    <xsl:value-of select="ServiceName"/>
> > 		  </td>
> > 		  <td>
> > 		    <xsl:value-of select="TimesPerDay"/>
> > 		  </td>
> > 	      </tr>
> > 	 </xsl:if>
> > 								 <xsl:if test="not(position() = 1)">
> > 	   <tr>
> > 	     <td colspan="2"/>
> > 		<td>
> > 		  <xsl:value-of select="ServiceName"/>
> > 		</td>
> > 		<td>
> > 		  <xsl:value-of select="TimesPerDay"/>
> > 		</td>
> > 	   </tr>
> > 	 </xsl:if>
> >    </xsl:if>
> > </xsl:for-each>
> > </xsl:if>
> > </xsl:for-each>
> > 
> > </table>
> > </html>
> > </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>
> 
=== message truncated === 

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

Disclaimer

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.