[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Parameterized sort

Subject: RE: Parameterized sort
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 1 Apr 2003 15:58:42 +0100
parameterized xsl sort
You've got your knickers in a twist. You want

<xsl:sort select="column[@name=$sortByColumn]"/>

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


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Kim Tran
> Sent: 01 April 2003 14:25
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Parameterized sort
> 
> 
> I have the following sort problem where I want to have the 
> sort key defined 
> as a parameter.
> 
> For example, here is my XML:
> <document>
> <row><column name="FirstName">John</column>
>       <column name="LastName">Doo</column>
> </row>
> <row><column name="FirstName">Alice</column>
>       <column name="LastName">Mulcaster</column>
> </row>
> 
> I want to sort the list by either FirstName or LastName.  
> Here is my xsl 
> file:
> 
> <?xml version="1.0" encoding="ISO-8859-1"?>
> <xsl:stylesheet
>   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>   version="1.0" xmlns:xalan="http://xml.apache.org/xalan">
> <xsl:output method="xml"/>
> 
> <xsl:param name="sortByColumn" select="'FirstName'"/> 
> <xsl:template match="/"> <Document> <xsl:for-each 
> select="Document/row"> <xsl:sort 
> select="column[@name=*[name()=$sortByColumn]]"/>
> <row>
>   <xsl:apply-templates select="column"/>
> </row>
> </xsl:for-each>
> </Document>
> </xsl:template>
> 
> <xsl:template match="column">
> <xsl:copy-of select="."/>
> </xsl:template>
> </xsl:stylesheet>
> 
> However, it still doesn't work.  I know that the sort key if 
> defined as 
> parameter, I should use "xalan:evalue($sortKey)" or "*[name() 
> = $sortKey]".  
> In this case, I want to sort the rows by the FirstName column 
> or by LastName 
> column and First Name.
> 
> If I say,
> <xsl:sort select="column[@name='FirstName']"/>
> then, it works properly.
> 
> Many thanks in advance.
> 
> 
> 
> 
> 
> _________________________________________________________________
> Add photos to your messages with MSN 8. Get 2 months FREE*.  
> http://join.msn.com/?page=features/featuredemail
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 


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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.