This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Arbitrary sorting


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]