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

Tyro grouping and nesting problem

Subject: Tyro grouping and nesting problem
From: Jon Crump <jjcrump@xxxxxxxxxxxxxxxx>
Date: Fri, 11 Feb 2005 10:46:37 -0800 (PST)
jon crump
Being a complete xsl tyro as I am, I know I'm making some sort of conceptual error. This is clearly the wrong way to go about this. Has anybody got a clue for the clueless?

Starting with an xml file like this:
<body>
	<item>
		<date>today</date>
		<name>James</name>
		<place>market</place>
	</item>
	<item>
		<date>today</date>
		<name>Joe</name>
		<place>work</place>
	</item>
	<item>
		<date>today</date>
		<name>Joe</name>
		<place>school</place>
	</item>
	<item>
		<date>tomorrow</date>
		<name>Jean</name>
		<place>home</place>
	</item>
	<item>
		<date>thenextday</date>
		<name>Jon</name>
		<place>work</place>
	</item>
</body>

This is the result I want to get:
<body>
	<today>
		<item>
			<date>today</date>
			<name>James</name>
			<place>market</place>
		</item>
		<item>
			<date>today</date>
			<name>Joe</name>
			<place>work</place>
		</item>
		<item>
			<date>today</date>
			<name>Joe</name>
			<place>school</place>
		</item>
	</today>
	<tomorrow>
		<item>
			<date>tomorrow</date>
			<name>Jean</name>
			<place>home</place>
		</item>
	</tomorrow>
	<thenextday>
		<item>
			<date>thenextday</date>
			<name>Jon</name>
			<place>work</place>
		</item>
	</thenextday>
</body>

Using the Muenchian method, I've been able to identify unique values for item/date thus:
<xsl:key name="items" match="item" use="date"/>
<xsl:template match="/">
<xsl:param name="uniquedates" select="//item[generate-id(.)=generate-id(key('items',date))]"/>
<xsl:for-each select="$uniquedates">
<xsl:element name="{string(date)}">
<xsl:copy-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:template>


But, since $uniquedates returns a node set containing only three nodes, I can't figure out how to populate the new elements with all of its appropriate children, so I get this:
<body>
<today>
<item>
<date>today</date>
<name>James</name>
<place>market</place>
</item>
</today>
<tomorrow>
<item>
<date>tomorrow</date>
<name>Jean</name>
<place>home</place>
</item>
</tomorrow>
<thenextday>
<item>
<date>thenextday</date>
<name>Jon</name>
<place>work</place>
</item>
</thenextday>
</body>
I know I'm missing something obvious here. Any sort of clue would be welcome.
__________
J.J. Crump
Dept. of History 353560
University of Washington
Seattle, WA. 98195


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.