473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

XSL Sort

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

Original.xml

<Root>

<Car>
<Name>Ford</Name>
<DealerRating>3</DealerRating>
<MyRating>1</MyRating>
</Car>
<Car>
<Name>Honda</Name>
<DealerRating>4</DealerRating>
<MyRating>5</MyRating>
</Car>
<Car>
<Name>Nissan</Name>
<DealerRating>7</DealerRating>
<MyRating>3</MyRating>
</Car>
</Root>

Note:
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

Result.xml

<Root>

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

</Root>

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

<if:position()=1>
Then write name1="XXX" and rating1="XXX"
</if>
<if position()=2>
Then write name2="XXX" and rating2="XXX"
</if>
<if position()=3>
Then write name3="XXX" and rating3="XXX"
</if>
</xsl:for-each>


Any suggestions would be appreciated.
Thanks,
Santa.

Nov 29 '05 #1
1 1665
aerotops wrote:
Hi,
I am trying to sort something using XSLT. I am going to give examples.

Original.xml

<Root>

<Car>
<Name>Ford</Name>
<DealerRating>3</DealerRating>
<MyRating>1</MyRating>
</Car>
<Car>
<Name>Honda</Name>
<DealerRating>4</DealerRating>
<MyRating>5</MyRating>
</Car>
<Car>
<Name>Nissan</Name>
<DealerRating>7</DealerRating>
<MyRating>3</MyRating>
</Car>
</Root>

Note:
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.
But what if DR=2 and MR=3? Is the rating then 3 or 2?
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

Result.xml

<Root>

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

</Root>

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

<if:position()=1>
Then write name1="XXX" and rating1="XXX"


<xsl:attribute name="name1">
<xsl:value-of select="Name"/>
</xsl:attribute>
<xsl:attribute name="rating1">
<xsl:value-of select="rating"/>
</xsl:attribute>

Presumably you have generated a composite value for <rating> somewhere.

You can find more help on the XSL List (http://www.mulberrytech.com)

///Peter
--
XML FAQ: http://xml.silmaril.ie/
Nov 29 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Philips | last post by:
I recently had the need to sort a large number of lists of lists, and wondered if an improvement to the Decorate-Sort-Undecorate idiom is in the works. Ideally, I would like to sort the list of...
1
by: Kamilche | last post by:
I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None,...
4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
40
by: Elijah Bailey | last post by:
I want to sort a set of records using STL's sort() function, but dont see an easy way to do it. I have a char *data; which has size mn bytes where m is size of the record and n is the...
7
by: Stuart | last post by:
The stl::sort() that comes with Dev Studio 6 is broken (it hits the degenerate case in a common situation). I have a replacement. I would like to globally do "using namespace std; except use my...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
10
by: Woody Ling | last post by:
In 32 bits DB2 environment, is it meaningful to set sheapthres larger than 256MB for the following case.. 1. Intra-parallel is ON 2. Intra-parallel is OFF
5
by: neehakale | last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort. I got an idea,in which situation we can use...
5
by: neocortex | last post by:
Hello! I am a newbie in Python. Recently, I get stuck with the problem of sorting by two criteria. In brief, I have a two-dimensional list (for a table or a matrix). Now, I need to sort by two...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.