Variation on a Grouping Question

Subject: Variation on a Grouping Question
From: Raj Muchhala <rmuchhala@xxxxxxxxxxxxxx>
Date: Tue, 19 Sep 2000 10:50:09 -0500
Hi All,

OK, I know I have a grouping problem and the FAQ has been very helpful up
this point. But
now I'm stuck... 

Given XML code like the following:

<z:row job_number='14002' city='Milwaukee' state='WI' qty='14687'
	 date='01/01' />
<z:row job_number='14000' city='Buffalo' state='NY' qty='14687'
	  date='01/01' />
<z:row job_number='14001' city='Milwaukee' state='WI' qty='14687'
	 date='01/01'  />
<z:row job_number='14000' city='Buffalo' state='NY' qty='14687'
	 date='01/01' />
<z:row job_number='14002' city='Buffalo' state='NY' qty='14687'
	 date='01/01' />
<z:row job_number='14000' city='New York' state='NY' qty='14687'
	 date='01/01' />
<z:row job_number='14002' city='Buffalo' state='NY' qty='14687'
	 date='01/01' />
<z:row job_number='14002' city='Milwaukee' state='WI' qty='14687'
	 date='01/01'  />

I want to output:

<i>Job Number: 14002</i>
<tr><td><b>Milwaukee</b></td></tr>	
<tr><td>Date:01/01</td><td>qty: 14687</td></tr>
<tr><td>Date:01/01</td><td>qty: 14687</td></tr>
<tr><td><b>Buffalo</b></td></tr>
<tr><td>Date:01/01</td><td>qty: 14687</td></tr>

Where:  Job Number is passed in as a parameter.

According to Jeni's FAQ, the logic of Muenchian method for getting the
grouping of cities would
run as follows:  

-->  Give me the 1st occurance of 'City' in the node list returned by
indexing the 'by_city' key on the
value of @city attribute

But the logic for my task is:

-->  Within the subset of Job Numbers such that 'job_number = $parm', give
me the 1st occurance
of 'City' in the node list etc....

My solution was to immediately restrict the node-list returned by the key by
something like:

<xsl:key name="by_city" match="/xml/rs:data/z:row[@job_number = $job]"
use="@city" />  

Since parameters cannot be used in xsl:key, this fails (hard-coding does
work).... Am I approaching this wrong?  
The non-functioning template is below....

Thanks in advance for your help,

-Raj

----------------- Template ------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0"
	xmlns:msxsl='urn:schemas-microsoft-com:xslt'
	xmlns:rs='urn:schemas-microsoft-com:rowset'
	xmlns:z='#RowsetSchema'
	xmlns:test='urn:mytest'>
<xsl:param name="job" select="'46521'"/>
<xsl:key name="by_city" match="/xml/rs:data/z:row[@job_number = $job]"
use="@city" />

<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>

<!-- ************************************************** -->
<xsl:template match="rs:data">

<xsl:apply-templates select="*[@city and
generate-id(.)=generate-id(key('by_city', @city))]"> 
	<xsl:sort select="@city" />
</xsl:apply-templates>

</xsl:template>

<!-- ************************************************** --> 
<xsl:template match ="*[@city]">

<tr>
	<td><xsl:value-of select="@city"/></td>
</tr>

<xsl:for-each select
="/xml/rs:data/z:row[@job_number[.=$job]][@city=current()/@city]">
<tr>
<td>Date:<xsl:value-of select="@date"/></td>
<td>Qty:<xsl:value-of select="@qty"/></td>
</tr>
</xsl:for-each>

</xsl:template>



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


Current Thread