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

RE: grouping by unique...

Subject: RE: grouping by unique...
From: "Fei Zheng" <Fei.Zheng@xxxxxxx>
Date: Wed, 18 Jun 2003 13:22:06 -0400
preceding sibling unique
Thanks to those who replied! 

Oh well, Muenchian technique and the common way outputs the different result which seems they both giving unique solutions, but the one that Muenchian has a shorter list than the other one. But I really want to use Muenchian due to the large amount of the nodes. Anything wrong with my code? Thanks a lot!!

<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1">

<xsl:key name="solution-key" match="metadata" use="solution" />	

<xsl:template match="report">
	<!-- using Muenchian technique to display a list of unique solutions -->
	<xsl:apply-templates select="item">
		<xsl:sort select="metadata/solution/."/>
	</xsl:apply-templates>

	<!-- using common grouping to display a list of unique solutions --> 
	<xsl:variable name="unique-solutions" 
		select="item/metadata/solution[not(. = preceding::solution)]"/>
	<xsl:for-each select="$unique-solutions">
		<xsl:sort select="." />
		<xsl:value-of select="."/>
	</xsl:for-each>	
</xsl:template>

<xsl:template match="item">
	<xsl:for-each select="metadata[generate-id(.) = generate-id(key('solution-key', solution)[1])]">
		<xsl:value-of select="solution/."/>
	</xsl:for-each>
</xsl:template>

Again, XML file:
<report>
	<item>
		<content>
			....
		</content>
		<metadata>
			<solution>A</solution>
			<solution>B</solution>
			<solution>C</solution>
		</metadata>
	</item>
	<item>
		<content>
			.....
		</content>
		<metadata>
			<solution>A</solution>
			<solution>B</solution>
			<solution>D</solution>
		</metadata>
	</item>
	<item>
		<content>
			.....
		</content>
		<metadata>
			<solution>B</solution>
			<solution>D</solution>
			<solution>E</solution>
		</metadata>
</report>	
						
					
										

-----Original Message-----
From: Lars Huttar [mailto:lars_huttar@xxxxxxx]
Sent: Tuesday, June 17, 2003 10:44 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  grouping by unique...


> Fei Zheng wrote:
> 
> > I'd like to have an unique solution list.  Anyone can tell what's
>  > wrong with the following code which gives all solutions instead of
>  > the unique solutions?
> >     	      select="item[not(metadata/solution = 
> preceding-sibling::metadata/solution)]/metadata/solution"	/>
> 
> You are using the preceding-sibling on the wrong element.
> Try
>    select="item/metadata/solution[not(. = 
> preceding-sibling::solution)]"/>
> 
> J.Pietschmann

But this will not give the right results because it only checks
for *siblings* that are the same, whereas Fei Zheng wants to
eliminate duplicates that are second cousins too.

How about
  select="item/metadata/solution[not(. = preceding::solution)]"

Or go Muenchian. (Btw how do you pronounce that?)

Lars


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


 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.