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

RE: Sorting on different elements...

Subject: RE: Sorting on different elements...
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Thu, 22 Jan 2004 10:32:26 -0000
xslt sort different elements
> Hi,
> 
> Sorry if this has been asked before - or is a daft question.
> 
> Is it possible to parameterise an <xsl:sort> ?
> 
> Example.
> 
> 	<root>
> 		<data>
> 			<firstname value="Fred"/>
> 			<lastname value="Smith"/>
> 		</data>
> 		<data>
> 			<firstname value="Tom"/>
> 			<lastname value="Jones"/>
> 		</data>
> 		<data>
> 			<firstname value="Myles"/>
> 			<lastname value="Ward"/>
> 		</data>
> 		...
> 	</root>
> 
> Sometimes I want to sort <data> on "firstname/@value" 
> sometimes on "lastname/@value" based on a user parameter of some kind.
> 
> Is this possible?

You will need to an extension function if you want to evualate an xpath
at run time, so if you have:

 <xsl:param name="sortParam" select="'lastname/@value'"/>

Where you pass in the sort criteria as a parameter, you would need to
use:

 <xsl:sort select="saxon:evaluate($sortParam)"/>

The evaluate() extention function will turn a string into an xpath.


If your data was simple enough, or more to the point your sort criteria
was simple enough, such as a single element name:

 <xsl:param name="sortParam" select="'lastname'"/>

Then you can get away without using an extension functions, such as:

 <xsl:sort select="*[local-name() = $sortParam]/@value"/>

I think this still applies for xslt 2.0.

Cheers
andrew

 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.