Wrox Programmer Forums
|
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 March 12th, 2009, 09:55 AM
Friend of Wrox
 
Join Date: Feb 2009
Posts: 119
Thanks: 25
Thanked 3 Times in 3 Posts
Default Sorting

If I want to sort a list of countries by their name eg

<xsl:for-each select="countries/country">
<xsl:sort select="name"/>
<xsl:variable name="this" select="."></xsl:variable>
<xsl:variable name="next" select the next country in this sorted list</xsl:variable>

How can I get the next sorted item, i tried using following/following sibling but that only get the next country in the original xml document.
 
Old March 12th, 2009, 10:02 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you use XSLT 2.0 then simply sort into a variable e.g.

Code:
<xsl:variable name="sortedCountries">
<xsl:for-each select="countries/country">
                <xsl:sort select="name"/>
<xsl:copy-of select="."/>
</xsl:variable>
then process the sorted elements in the variable and following-sibling should give you the following sibling in sort oder.

If you are using XSLT 1.0 then you can also sort into a variable but you need to use an extension function like exsl:node-set first on the variable before you can use XPath like following-sibling on that.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
JohnBampton (March 12th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Please Help Me sorting this nj.nikhil BOOK: Beginning ASP 3.0 1 November 10th, 2006 03:45 PM
Sorting sunny76 Excel VBA 2 September 19th, 2005 09:31 PM
sorting kondapally Crystal Reports 2 January 21st, 2005 10:51 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Sorting? pbernardo XSLT 2 October 27th, 2003 11:34 AM





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