This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Parametrized xsl:sort
- From: Peter Davis <pdavis152 at attbi dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Cc: "Neale Morison" <nmorison at ozemail dot com dot au>
- Date: Thu, 29 Aug 2002 22:31:46 -0700
- Subject: Re: [xsl] Parametrized xsl:sort
- References: <000401c24fda$462bb6d0$a0f26840@cisco.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
On Thursday 29 August 2002 21:03, Neale Morison wrote:
> Thanks. I thought I might be able to do it without an eval, but the eval
> method does work. Regards,
> Neale
The only other way to do it is to have a preset list of possible sort keys,
and use <xsl:choose>. It's not as useful, but it will work without the
extension.
<xsl:call-template name="petTable">
<xsl:with-param name="selection"
select="pet[@species='dog']"/>
<!-- use quotes around '@name' -->
<xsl:with-param name="sortkey" select="'@name'"/>
<xsl:with-param name="sortorder" select="'descending'"/>
</xsl:call-template>
<xsl:template name="petTable">
<xsl:param name="selection" select="*"/>
<xsl:param name="sortkey" select="''"/>
<xsl:param name="sortorder" select="''"/>
...
<xsl:choose>
<xsl:when test="$sortkey = '@name'">
<xsl:apply-templates select="$selection">
<!-- just a question, did you mean to parameterize the
sort order as well? -->
<xsl:sort select="@name" order="descending"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="$sortkey = 'something else'">
<!-- copy the same apply-templates here, changing @name
as appropriate -->
</xsl:when>
</xsl:choose>
..>
</xsl:template>
--
Peter Davis
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list