RE: [xsl] grouping by unique...

Subject: RE: [xsl] grouping by unique...
From: "Fei Zheng" <Fei.Zheng@xxxxxxx>
Date: Wed, 18 Jun 2003 13:22:06 -0400
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: [xsl] 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