Re: [xsl] How to change Sort keyword dynamicly

Subject: Re: [xsl] How to change Sort keyword dynamicly
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 19 May 2001 09:17:28 +0100
Hi,

I'm not sure what you're trying to achieve exactly - what kind of
value does the $sortField parameter get set to?  The default value
that you've given:

> <xsl:param name="sortField" select="node(//title)"/>

Isn't proper XPath syntax (your processor should object to it).

I think that you probably want it to be a string:

  <xsl:param name="sortField" select="'title'" />

The value of the select attribute on xsl:sort is an expression that
gives the sort value that should be used for a particular node when
you sort it.  So it has to be a path that's dependant on the current
node (the node that's being sorted).

In this case I'll assume that the values you want to sort by are given
by element children of the book elements that you're sorting. Normally
you could sort by title with:

  <xsl:for-each select="book">
     <xsl:sort select="title" />
     ...
  </xsl:for-each>

You want the thing that you're sorting by to be determined by the
$sortField parameter.  You want to select the child element of the
book element that is called whatever is specified by the $sortField
parameter.  You can do this by selecting all the child elements and
filtering them with a predicate to get the one whose local-name() is
equal to $sortField:

  <xsl:for-each select="book">
     <xsl:sort select="*[name() = $sortField]" />
     ...
  </xsl:for-each>

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread