[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Dynamic XSL Sorting - Is there a way like this?


Subject: RE: [xsl] Dynamic XSL Sorting - Is there a way like this?
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 24 Jul 2002 09:13:53 +0100

> The issue is the sort.  If I use and hard code the following 
> it works: <xsl:for-each 
> select="HRISReport/Participants/Participant/Plans/Plan/Contrib
> utionRateChanges/C
> ontributionRateChange/RateChanges/RateChange">
> 	<xsl:sort select="../../../../../../LastName"/>
> 	<xsl:sort select="../../../../../../@SSN"/>
> 	
> This sorts properly but if I try to pass in a parameter 
> things start to fail.
> 
> The following works:
> <xsl:param name="sortBy" select="'Name'"/>
> 
> works if the sort reads:
> <xsl:sort select="@*[name(.)=$sortBy]"/>
> 
> <xsl:param name="sortBy" select="'OldPercent'"/>
>  works if the sort reads:
> <xsl:sort select="*[name(.)=$sortBy]"/>
> 
> But how do I sort off of LastName,FirstName or SSN as a 
> parameter.  None of these fields appear to work unless I 
> hardcode the sort. 

One solution is to use xx:evaluate(), which evaluates any XPath
expression supplied as a string. This is available in some processors
including Saxon and Xalan.

You might also be able to achieve the required effect with a generic
expression that searches for an ancestor having a child or attribute
with the right name:

<xsl:sort select="(ancestor-or-self::*/* | ancestor-or-self::*/@*)
                   [name()=$param][last()]"/>

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


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



Current Thread
Keywords