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

Re: dynamic sorting

Subject: Re: dynamic sorting
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 05 Feb 2004 10:37:11 -0500
xslt dynamic sorting
At 2004-02-05 16:02 +0100, Peter Billen wrote:
Imagine the following part of an xml file:

<person>
        <fname>Jup</fname>
        <lname>Nope</lname>
        <bday>Also</bday>
        ...
</person

The following works perfect:

<xsl:template match="/">
        <xsl:apply-templates select="person">
                <xsl:sort select="person/fname"/
        </xsl:apply-templates>
</xsl:template>

I can't imagine how that works ... you are sorting a node set of element nodes named person, but the criterion for the sort is the fname child of person child of person, and I don't see that your person elements have any children named person.


But when I put the string "person" into a parameter named "sort", it doesn't
work anymore:

<xsl:template match="/">
        <xsl:param name="sort">person</xsl:param>

That declares the string "person". To default the argument to a node set, do the following:


<xsl:param name="sort" select="person"/>

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.

"preferred"? Parameters passed are strings, not node sets.


You will probably need something lie:

<xsl:apply-templates select="/*/*[name(.)=$sort]"/>

... or some such to accept a string as the name of an element type whose elements are to be sorted. But you might then have problems with the sort criteria.

You'll need to share more information to get more help.

....................... Ken

--
Public courses: sign up for one or both soon to reserve your seat!
Each week:  Monday-Wednesday: XSLT/XPath;  Thursday-Friday: XSL-FO
Washington, DC: 2004-03-15           San Francisco, CA: 2004-03-22
Hong Kong, China: 2004-05-17           Bremen, Germany: 2004-05-24
World-wide on-site corporate, government & user group XML training

G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc


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.