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

Re: sort by predefined order

Subject: Re: sort by predefined order
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 20 May 2008 09:18:49 +0100
Re:  sort by predefined order
2008/5/20 Michael Kay <mike@xxxxxxxxxxxx>:
> <xsl:sort select="index-of($sortorder, @ID)"/>
>
> where
>
> <xsl:variable name="sortorder"
>  select="for $t in tokenize(/source/sortorder, ',\s*') return
> xs:integer($t)"/>
>
> This isn't going to be very efficient if sortorder is a long list, in that
> case you probably want to use keys to speed it up.

I would've tended towards that route anyway - not using sort at all.
So modifying the above a bit you get:

<xsl:key name="element-by-ID" match="element" use="@ID"/>

<xsl:for-each select="for $t in tokenize(/source/sortorder, ',\s*')
return xs:integer($t)">
  <xsl:apply-templates select="key('element-by-ID', .)"/>
</xsl:for-each>

or perhaps

<xsl:apply-templates select="for $t in tokenize(/source/sortorder,
',\s*') return key('element-by-ID', xs:integer($t))"/>


-- 
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

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.