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

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
muchhala
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

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.