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

RE: Multiple Grouping & Muenchian Method

Subject: RE: Multiple Grouping & Muenchian Method
From: "Jacoby, Peter R." <PJACOBY@xxxxxxxxxxxx>
Date: Fri, 21 Jul 2006 15:17:17 -0400
muenchian method parameter
>>Is it possible to have a group within a group.

Hi, Steve,

You were really close in your code.  The concept that you were missing is to
define one xsl:key with two parameters using the concat function.

If you change your key declaration to be
<xsl:key name="byDateAndCountry" match="entry"
use="concat(parent::group/parent::date/text(), country)" />
or more succinctly:
<xsl:key name="byDateAndCountry" match="entry" use="concat(../../text(),
country)" />

You can then call one key indexed by an entry's date as well as country.

A full stylesheet is below.  Please let us know if you have any other
questions.
This all becomes a lot easier in 2.0 with xsl:for-each-group.  Hopefully
someone
will post the 2.0 solution so we can see how much simpler it is.

-Peter

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes"
encoding="UTF-8"/>

<xsl:key name="byDateAndCountry" match="entry" use="concat(../../text(),
country)" />

<xsl:template match="/">
	<table border="1">
		<xsl:apply-templates select="report/table/date"/>
	</table>
</xsl:template>

<xsl:template match="date">
	<tr>
		<td>
			<xsl:value-of select="normalize-space(text())" />
		</td>
	</tr>

	<xsl:for-each select="group/entry[generate-id() =
generate-id(key('byDateAndCountry', concat(../../text(), country))[1])]">
		<tr>
			<td>
				<xsl:value-of select="country" />
			</td>
		</tr>
		<tr>
			<td>Group</td>
			<td>Name</td>
			<td>ID</td>
		</tr>
		<xsl:apply-templates select="key('byDateAndCountry',
concat(../../text(), country))" />
	</xsl:for-each>
</xsl:template>

<xsl:template match="entry">
	<tr>
		<td>
			<xsl:value-of select="../@type" />
		</td>
		<td>
			<xsl:value-of select="name" />
		</td>
		<td>
			<xsl:value-of select="id" />
		</td>
	</tr>
</xsl:template>

</xsl:stylesheet>

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.