xsl-list
[Top] [All Lists]

Re: dynamic sorting

2004-02-05 08:37:11
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(_at_)CraneSoftwrights(_dot_)com
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