Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Display Modes
  #1 (permalink)  
Old November 29th, 2005, 03:09 PM
Registered User
Join Date: Nov 2005
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting in XSLT

I am trying to sort something using XSLT. I am going to give examples.




1. The number of cars is limited to 3.
2. <DealerRating> has a higher priority than <MyRating> as long as DR>0 (Not 0). For example, if DR=3 and MR=2, then rating =3. Or if DR=0 and MR=1, now however, rating =1 because DR=0.
3. Apply some XSLT to Original.xml to get the following Result.xml



            <Car name1="Ford" rating1="1" name2="Nissan" rating2="3" name3="Honda" rating3="5"/>


As you can see, the attributes are generated by sorting the <Car> elements in Original.xml in ascending order of rating as described above.
Right now, I am doing this using dom4j. I would like to do this in XSLT.

Note: Don't worry about the XSLT logic which compares <MyRating> and <DealerRating> and then gives me a rating. I have already done that.

My problem is that I would like to sort on the rating1, rating2 and rating3 attributes.

Some pseudocode for my XSLT sorting part (Right now, I parse the Original.xml file using dom4j. Then, I add a <rating> element to the Original.xml after deciding which rating to use in each <Car> element. I don't want to change the Original.xml by inserting my rating attribute.):

<xsl:for-each select="Car">

<!-- <xsl:sort> on <rating> which I get from my Java code

Then write name1="XXX" and rating1="XXX"
<if position()=2>
Then write name2="XXX" and rating2="XXX"
<if position()=3>
Then write name3="XXX" and rating3="XXX"

Any suggestions would be appreciated.

Reply With Quote
  #2 (permalink)  
Old November 30th, 2005, 04:37 AM
Authorized User
Join Date: Oct 2005
Location: , , Philippines.
Posts: 72
Thanks: 0
Thanked 0 Times in 0 Posts

apply template on Root, then create 3 variables to in the ratings (use position here). then using xsl:if then else or xsl:choose find the case of the sorting order then create the element for car and the reference for the three cars will be easy on that after.
hope this helps.

Reply With Quote

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting on date column in XSLT Palwi XSLT 1 March 18th, 2008 07:19 AM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 08:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
pre-sorting in XSLT - help! thebnut XSLT 6 April 6th, 2004 07:45 AM

All times are GMT -4. The time now is 10:20 PM.

Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.