This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Arbitrary sorting
- To: Matthew Bentley <Matthew dot bentley at brookers dot co dot nz>
- Subject: Re: Arbitrary sorting
- From: Jeni Tennison <jeni at friday dot u-net dot com>
- Date: Thu, 03 Aug 2000 21:18:05 +0100
- Cc: "'XSL-List at mulberrytech dot com'" <XSL-List at mulberrytech dot com>
- Reply-To: xsl-list at mulberrytech dot com
Matt,
> Is it possible to do arbitrary sorting after alphabetical sorting,
>in XSLT?
It's certainly possible to have several sorts, and there aren't any
limitations on the types of sorts that you can have following other sorts.
Here is a solution given your example (though perhaps it's not
demonstrating the abitrariness that you're after - perhaps you can provide
another example to show the breadth of problems you're talking about).
First, sort on the first letter in the string:
<xsl:sort select="substring-before(., ' ')" />
Then sort so that any string containing 'v' is before those that do not:
with a data-type of 'number', booleans should be translated automatically
to 1 if true and 0 if false. It looks as though SAXON 5.4 isn't doing
this, so I've included an explicit call to number() which you may be able
to take out with your processor:
<xsl:sort select="number(contains(., 'v'))"
data-type="number"
order="descending" />
Finally, sort alphabetically.
<xsl:sort select="." />
I hope this helps,
Jeni
Dr Jeni Tennison
Epistemics Ltd * Strelley Hall * Nottingham * NG8 6PE
tel: 0115 906 1301 * fax: 0115 906 1304 * email: jeni.tennison@epistemics.co.uk
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list