Re: [xsl] dynamic sorting

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


The following works perfect:

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

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.
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness

XSL-List info and archive:

Current Thread