[xsl] Sorting problem

Subject: [xsl] Sorting problem
From: "Alex Scott" <fastidiously@xxxxxxxxxxx>
Date: Fri, 03 Sep 2004 15:46:31 +0100
Hi There,

My brain is getting a bit mangled with some sorting. Should I be using a
system of grouping? I want to avoid going through multiple pipelines.

I am trying to group a set based on a list of fruits (Filtered down from
using a lookup table)

I then want to take each fruits and sort it based on an order of
ascending quality. (The Order is defined in another lookup).

Then if there is more than one 'quality' of the same type for an
individual fruit ie. bad apple below, I just want to display a count.
This is how I would like it to look:

apple: bad(2),good
orange: good
satsuma: bad,good,excellent

Below is a summary of the code that is not working - basically losing
fruit depending on the XML ie.:

apple: bad(2),good
orange: good
satsuma: 

<xsl:for-each select="Go through fruit nodes in the XML">                
<xsl:sort select="Sort them based on the order of quality defined in the
lookup table"/>
<xsl:variable name="count" select="Count from the XML how many
replications there are of the the same quality for each fruit"/>
<xsl:variable name="lastQuality" select="Get the quality level for each
fruit"/>
<xsl:if
test="not(preceding-sibling::fruit[@quality=$lastQuality]/@quality)">
	<xsl:value-of select="@quality"/>
		<xsl:if test="$count>1">
		(<xsl:value-of select="$count"/>)
		</xsl:if><br/>
		</xsl:if>
	</xsl:for-each>

Current Thread