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 December 3rd, 2004, 03:39 PM
Registered User
 
Join Date: Dec 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT-- xsl:sort help...

I have the following structure...
<value>
<item priority ="2"> First </item>
<item priority ="1"> Second </item>
<item priority ="1"> Third </item>
<item priority ="3"> Fourth </item>
<item > Fifth </item>
<item > Sixth </item>
</value>

Is it possible for me to do sorting using xsl:sort where 'item' with priority ="1" should come first and those with priority ="2", then those item which does not have a priority attribute and then item with priority >=3 (3,4,5,6.....).


If u have any other way of sorting, plzz lemme know.

TIA,
debo
 
Old December 3rd, 2004, 03:58 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

You're splitting it up kinda like so I guess:
Inside the value template:
<xsl:apply-templates select="item[@priority=1]"/>
<xsl:apply-templates select="item[@priority=2]"/>
<xsl:apply-templates select="item[not(@priority)]"/>
<xsl:apply-templates select="item[@priority &gt;=3]"/>

is this what you're looking for?

 
Old December 3rd, 2004, 04:25 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0

xsl:sort select="number((@priority, 2.5)[1])"

In 1.0 conditional expressions are more difficult, but you can use the substring() trick:

substring("2", 1, boolean(@priority)) is "2" if @priority exists, "" otherwise, so your sort key is

select="concat(@priority, substring('2.5', 1, boolean(@priority)*3))"
data-type="number"



Michael Kay
http://www.saxonica.com/





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Xsl to Sort the following simple xml: Takashi321 XSLT 3 August 27th, 2007 11:54 AM
XSLT Dynamic xsl:sort Method kwilliams XSLT 2 July 20th, 2005 03:19 PM
xsl:sort Question kwilliams XSLT 6 July 18th, 2005 08:39 AM
Unable to sort using xsl sort command sly_jimmy_boy XSLT 3 June 17th, 2005 05:15 AM
xsl:sort and IE 5.0 Issue babloo81 XSLT 1 March 17th, 2004 06:12 AM





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