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

Dynamic Sorting

Subject: Dynamic Sorting
From: Ben Macaulay <bmacaula@xxxxxxxxxx>
Date: Thu, 07 Nov 2002 12:34:07 -0700
ben macaulay
Question -> Can you define a template that allows you to define, at
runtime, the elements that you want to sort on?  For instance, we have
an XML document as follows.

    <records>
        <contact id="0001">
            <title>Mr</title>
            <forename>John</forename>
            <surname>Smith</surname>
        </contact>
        <contact id="0002">
            <title>Dr</title>
            <forename>Amy</forename>
            <surname>Jones</surname>
        </contact>
        ...
    <records>

What we want to do is sort by (surname, forename), or sort by (title,
surname), or whatever we decide on the day.  In our XSL, we would like
to be able to specify variables that dictate how the sorting should be
done.  For instance, consider the following XSL extract.

    <xsl:variable name="sort-by-element-1" value="surname" />
    <xsl:variable name="sort-by-element-2" value="forename" />

In reality we are not going to hard code the variable values like this,
but rather pull them in from another document by way of the document()
function, but that's not important right now.

The problem is, later on in the XSL we can't have <xsl:sort
select="{$sort-by-element-1}" /> since xsl:sort's select attribute
doesn't accept attribute value templates.  You can specify attribute
value templates for xsl:sort's other attributes, for instance the
article at
http://www.biglist.com/lists/xsl-list/archives/200012/msg00392.html
demonstrates how to dynamically specify a descending or ascending sort
order.  However you can't do this for the select attribute.  Short of
creating nonportable XSL by using saxon:evaluate() or xalan:evaluate() I
can't see a way around this.  Any suggestions?  Can this kind of dynamic
sorting be done at all?


Cheers,
Ben Macaulay
Senior Software Engineer
DHL Worldwide Express

 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.