Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2007, 05:01 PM
Authorized User
 
Join Date: Jun 2003
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to victorcorey
Default Dynamic column sorting

I'm very new to xml and xsl.

I'm trying to do something like this:

<xsl:choose>
    <xsl:when test="$cruiseSortCol = 'Itinerary'">
        <xsl:sort order="{$cruiseSortDir}" select="substring-before(Itinerary,'-')" data-type="{$cruiseSortType}" />
    </xsl:when>
    <xsl:otherwise>
        <xsl:sort order="{$cruiseSortDir}" select="*[name()=$cruiseSortCol]" data-type="{$cruiseSortType}" />
    </xsl:otherwise>
</xsl:choose>

Basically, I have a dynamic sort that works with parameters passed in, the problem is one of the columns is a string (ie. 7-day). I need to sort this column based on the number value (substring-before(Itinerary,'-')) works on its own, but I need to have different search criteria based on the column being passed in.

Any help would be appreciated.

Thanks,
vc

--
Victor Corey
__________________
--
Victor Corey
 
Old October 31st, 2007, 05:40 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Define two sort keys, in such a way that one of them has no effect:

<xsl:for-each select=".....">
  <xsl:sort order="{$cruiseSortDir}"
            select="*[$cruiseSortCol!='Itinerary'][name()=$cruiseSortCol]" data-type="{$cruiseSortType}" />

  <xsl:sort order="{$cruiseSortDir}" select="substring-before(Itinerary,'-')" data-type="{$cruiseSortType}" />


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting on date column in XSLT Palwi XSLT 1 March 18th, 2008 07:19 AM
Sorting a column yogeshyl Excel VBA 1 December 10th, 2007 07:09 PM
Grouping and (dynamic) sorting asearle XSLT 12 November 10th, 2006 10:51 AM
Sorting lists by clicking column labels isme XSLT 0 March 15th, 2006 04:40 PM
sorting a column alphabetically Adam H-W SQL Server 2000 8 November 11th, 2003 09:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.