RE: [xsl] Sorting Problem

Subject: RE: [xsl] Sorting Problem
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Wed, 12 Sep 2001 21:33:49 +0100
> I have the following example input XML doc :
>
> <records>
> 	<pupil>
> 		<name>Smith</name>
> 		<school>Oxford</school>
> 	</pupil>
> 	<pupil>
> 		<name>Jones</name>
> 		<school>Eton</school>
> 	</pupil>
> 	<pupil>
> 		<name>Davis</name>
> 		<school>Eton</school>
> 	</pupil>
> 	<pupil>
> 		<name>Jones</name>
> 		<school>Oxford</school>
> 	</pupil>
> 	<pupil>
> 		<name>Davis</name>
> 		<school>Oxford</school>
> 	</pupil>
> 	<pupil>
> 		<name>Davis</name>
> 		<school>Cambridge</school>
> 	</pupil>
> </records>
>
> And I want the output similar to :
>
> <records>
> 	<pupil>
> 		<name>Davis</name>
> 	</pupil>
> 	<pupil>
> 		<name>Jones</name>
> 	</pupil>
> 	<pupil>
> 		<name>Smith</name>
> 	</pupil>
> <records>
>
> Based on the frequency of the value in the <pupil> tag.

I think you need a two-pass approach (using a result tree fragment for the
intermediate results, and using the xx:node-set() extension to grab this as
input to the second pass.)

The first pass is a grouping problem: use either Muenchian grouping or
pupil[not(name=previous-sibling::pupil/name)] to get the distinct values,
and put these as nodes on the RTF, together with a count attribute that
indicates how often they occur.

The second pass is a sort: sort the nodes in the RTF using the count
attribute.

> Also I want to introduce a weighting system ...

Let's tackle that when you've done the first part.

Mike Kay
>


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


Current Thread