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

RE: Sorting Problem

Subject: RE: Sorting Problem
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Wed, 12 Sep 2001 21:33:49 +0100
xsl sibling school
> 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

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.