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

Re: dynamic sorting

Subject: Re: dynamic sorting
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 5 Feb 2004 15:30:50 GMT
dynamic sort xsl
This is a FAQ

  <xsl:param name="sort">person</xsl:param>
That makes $sort in to a result tree fragment consisting of a root node
and a text node with the string "person".

It's an error to query in to a result tree fragment and so
<xsl:apply-templates select="$sort">
is an error.
In XSLT2 it's not an error but it will apply templates to that new
document that just contains the string person and no element nodes, so
it will do the wrong thing.

If you had done
  <xsl:param name="sort" select="person"/>

then the sort param would have been the person element and so
<xsl:apply-templates select="$sort">
would be legal although then the current node would be the person
elements and so you probably would want

<xsl:sort select="fname"/>
rather than
<xsl:sort select="person/fname"/

unless person elements have a person child.

The whole thing looks suspicous as it is in a template for /
if you are in a well formed document there can only be one element child
of / and so you are sorting a list of one.

  My goal is that the user of my xsl file can give a parameter "sort" (to his
 xslt parser) which defines his preferred way of sorting.

so you will probably be passing in a string and you want to sort on an
element with that name, so faq answer is
<xsl:sort select="*[name()=$sort]"/>

But again you need to make sure you are sorting a list of more than one
thing 

David


-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 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.