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

grouping question

Subject: grouping question
From: "Blake, Stephen" <Stephen.Blake@xxxxxxxxxxxx>
Date: Fri, 23 Mar 2001 15:38:04 -0500
muench s grouping
Hello all,

I am having trouble with a grouping problem. I've checked a book and the faq
and I'm having a hard time figuring out how to do it. We have an input
source like this:

<domain>
	<host name="foo">
		<service name="svc1"/>
		<service name="svc2"/>
		<service name="svc3"/>
	</host>
	<host name="bar">
		<service name="svc2"/>
		<service name="svc4"/>
	</host>
	<host name="baz">
		<service name="svc1"/>
		<service name="svc4/>
		<service name="svc7"/>
	</host>
</domain>

We want to find all unique services, then iterate over them finding each
host that is running that service, generating somthing like this:

<p>Hosts running svc1:</p>
<ul>
	<li>foo</li>
	<li>baz</li>
</ul>
<p>Hosts running svc2:</p>
<ul>
	<li>foo</li>
	<li>bar</li>
</ul>
<p>Hosts running svc3:</p>
<ul>
	<li>foo</li>
</ul>
<p>Hosts running svc4:</p>
<ul>
	<li>bar</li>
	<li>baz</li>
</ul>
<p>Hosts running svc7</p>
<ul>
	<li>baz</li>
</ul>

So, looking through Steve Muench's excellent book, I see that Chapter 9 has
a very similar example, taking all unique developers and which bugs they
have assigned to them. I tried to modify his example, but the snag is that I
have multiple <service>s inside each <host> whereas in the example in the
book, there is only one <dev>eloper for each <bug>. Hmmm. The hardest thing
is finding the unique services, iterating over the hosts at that point I can
do using a key index.

Here's what I've tried so far:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes"/>
 
<xsl:key name="host-service-index" match="/domain/host" use="service"/>
<xsl:template match="/">
<xsl:for-each
select="/domain/host/service[generate-id(.)=generate-id(key('host-service-in
dex',.)[1]/service)]">
	<xsl:sort select="@name"/>
	<p>
	<b><xsl:value-of select="@name"/></b>
	<ul>
		<xsl:for-each select="key('host-service-index',.)">
			<li><xsl:value-of select="@name"/></li>
		</xsl:for-each>
	</ul>
	</p>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

But I only get one service like so:

<p>
	<b>svc1</b>
	<ul>
		<li>foo</li>
		<li>baz</li>
	</ul>
</p>

Can anyone help?

Thanks for your consideration.

Stephen Blake
Veritect
s t e p h e n . b l a k e @ v e r i t e c t . c o m

P.S. I'm using MS XML parser v 3.0, but I get the same results with
Infoteria iXSLT 2.0c and Instant-Saxon 6.0.2.


 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.