RE: sort

Subject: RE: sort
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Thu, 11 May 2000 13:43:32 +0100
> I am passing a parameter using
> processor.setStylesheetParam("S", "'name'");
> 
> Now in my style sheet I can access the parameter like this
> <xsl:value-of select="$S">
> but if I try to use this
> 
> <xsl:sort select="$S"> .. it doesn't work
>
I think it does work. The value of $S is the literal value 'name', so the
sort key for each member of the set is 'name', and when all members of the
set have the same sort key they are processed in document order.

I suspect what you want to do is to sort by the value of the child element
whose name is given in $S. Subject to small print involving namespaces, you
can do this as

<xsl:sort select="*[name()=$S]"/>

This is a FAQ. Note that the solution isn't general, for example it wouldn't
allow you to pass "@code" or "price * quantity" as the value of the sort
key. For a general solution, look at the Saxon extension function
saxon:evaluate(). Another solution is to modify the stylesheet before
execution: there's an example in my book of how to do this with MSXML3.

Mike Kay


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


Current Thread
  • RE: sort
    • Kay Michael - Thu, 11 May 2000 13:43:32 +0100 <=