ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
Re: [xsl] xsl sort: using element attribute as sort key!
by Omprakash V other posts by this author
Apr 17 2005 8:58PM messages near this date
RE: [xsl] xsl sort: using element attribute as sort key! | Re: [xsl] Measuring the complexity of XSLT stylesheets
& XSLT 

Hi,
         Your stylesheet would work if you didn't have the "@column=$sort"
in the select of xsl:sort. With the equals check, it is possibly ignoring
the select completely and ordering all the df_data nodes based on its
content and in  the order specified by the order attribute.

If  you would like to sort on the df_data nodes having attribute 'column'
it makes sense. If  you would like to sort based on df_data nodes having
attribute 'column' equals to 'name' then you need to have it in your
apply-templates than in the xsl:sort instruction.

You can get the desired result with

<xsl:sort select="df_data/@column" order="$dir"/> 

Cheers,
Omprakash.V







                                                                                            
                       
                    "Adam J                                                                 
                       
                    Knight"               To:     <xsl-list@[...].com>                       
          
                    <adam@brightid        cc:     (bcc: omprakash.v/Polaris)                
                       
                    ea.com.au>             Subject:     [xsl] xsl sort: using element attribu
te as sort key!        
                                                                                            
                       
                    04/18/2005                                                              
                       
                    05:58 AM                                                                
                       
                    Please respond                                                          
                       
                    to xsl-list                                                             
                       
                                                                                            
                       
                                                                                            
                       




Hi all,

I am trying to sort based on an elements attribute. Doesn't seem to work.
Can i do this, and if so, what am i doing wrong?
Replies greatly appreciated!

$sort parameter = 'name'
$dir parameter = 'descending'

xml structure:
<dfile> 
  <df_data_row> 
    <df_data column='name'> Value</df_data>
  </df_data_row> 
  <df_data_row> 
    <df_data column='phone'> Value2</df_data>
  </df_data_row> 
</dfile> 

<xsl:if test="$sort"> 
  <xsl:apply-templates select="dfile/df_data_row"> 
    <xsl:sort select="df_data/@column = $sort" order="$dir"> </xsl:sort>
  </xsl:apply-templates> 
</xsl:if> 

Cheers,
Adam



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@[...].com> 
--~--






This e-Mail may contain proprietary and confidential information and is sent for the intende
d recipient(s) only.
If by an addressing or transmission error this mail has been misdirected to you, you are req
uested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, dissemination, copying,
 disclosure, modification,
distribution and/or publication of this e-mail message, contents or its attachment other tha
n by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@[...].com> 
--~--

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved