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 March 24th, 2006, 04:02 PM
Authorized User
 
Join Date: Jan 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change Sort-by attribute based on parent

I have a list of level1 elements that contain level2 elements. Both have @name and @sort attributes. Is it possible to sort the level twos based on either @name or @sort depending on the value of the parent level1's @name?

 
Old March 24th, 2006, 04:53 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Easy in version 2.0:

<xsl:sort select="if (../@name = 'thing') then @name else @sort"/>

More convoluted in 1.0:

<xsl:sort select="@name[../../@name = 'thing'] |
                  @sort[../../@name != 'thing']"/>

(The first .. takes you back from the attribute to the level2 element, the second takes you back to the level1)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 24th, 2006, 05:00 PM
Authorized User
 
Join Date: Jan 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks as always for the speed & quality.






Similar Threads
Thread Thread Starter Forum Replies Last Post
sort on specific attribute kgoldvas XSLT 2 July 17th, 2007 09:42 AM
how to sort cross tab.sort based on row total joxa83 Crystal Reports 7 March 2nd, 2006 09:12 AM
Add attribute to the parent after checking child kinnur XSLT 10 May 30th, 2005 06:07 PM
Sort Records Based on Totals mvollmer Classic ASP Databases 1 July 11th, 2004 11:22 AM
xsl:sort- select attribute, syntax question Flashlight XSLT 3 August 14th, 2003 12:27 AM





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