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

RE: Sorting Using A Predefined Order

Subject: RE: Sorting Using A Predefined Order
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 21 Jun 2007 09:05:09 +0100
RE:  Sorting Using A Predefined Order
In 2.0, you just need to write a user-defined function that translates your
keys into numbers, for example January->1, February->2, and so on. The use
xsl:sort select="my:function(head)".

In 1.0 it's a bit more difficult because you can't call user-defined
functions within the select expression of xsl:sort. But you can usually
achieve the same thing by means of table-defined mapping. Given a document
months.xml such as

<doc>
  <month name="January" value="1"/>
  <month name="February" value="2"/> 

you can write 

<xsl:sort
select="document('months.xml')/doc/month[@name=current()/head]/@value"
data-type="number"/>

Michael Kay
http://www.saxonica.com/


> -----Original Message-----
> From: Jeff Sese [mailto:jsese@xxxxxxxxxxxx] 
> Sent: 21 June 2007 05:16
> To: Xsl-List
> Subject:  Sorting Using A Predefined Order
> 
> Hi,
> 
> Is it possible to sort some data according to a predefined ordering?
> 
> 
> I have a file like:
> 
> <root>
> <div>
>     <head>Some text 1</head>
> </div>
> <div>
>     <head>Some text 2</head>
> </div>
> <div>
>     <head>Some text 3</head>
> </div>
> <div>
>     <head>Some text <4/head>
> </div>
> <div>
>     <head>Some text 5</head>
> </div>
> </root>
> 
> and i want it sorted using this ordering:
> 
> Some text 2
> Some text 3
> Some text 5
> Some text 1
> Some text 4
> 
> Is the only solution to this is creating my own collation?
> 
> Thanks!
> -- Jeff

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.