This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Dynamic XSL Sorting - Is there a way like this?
- From: "Michael Kay" <michael dot h dot kay at ntlworld dot com>
- To: <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 24 Jul 2002 09:13:53 +0100
- Subject: RE: [xsl] Dynamic XSL Sorting - Is there a way like this?
- Reply-to: xsl-list at lists dot mulberrytech dot com
> 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@ntlworld.com
work: Michael.Kay@softwareag.com
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list