Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / November 2005

Tip: Looking for answers? Try searching our database.

XSL Sort

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
aerotops - 29 Nov 2005 20:22 GMT
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.
swapna guddanti [MSFT] - 30 Nov 2005 21:56 GMT
Looks like you need two passes on the input document to achieve this.
You can apply two transforms on the input document
The first one generates another xml document with the correct rating for
each car .
The second one can then use xsl:sort on the rating element of cars.

hope this helps,
swapna

> Hi,
> I am trying to sort something using XSLT. I am going to give examples.
[quoted text clipped - 72 lines]
> Thanks,
> Santa.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.