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
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 27th, 2003, 10:23 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sorting?

I'm new to XSLT so please bear with me.

I have XML looking like this.

<Event>
    <AirDateTime>10/24/2003</AirDateTime>
    <ArriveTime>10:00 AM</ArriveTime>
    <BeginTime>10:30 AM</BeginTime>
        <Location>House</Location>
    <State>FL</State>
    <Street>123 Biscanye Blvd.</Street>
        <City>Miami</City>
    <TimeZone>EST</TimeZone>
</Event>
<Event>
    <AirDateTime>10/24/2003</AirDateTime>
    <ArriveTime>10:30 AM</ArriveTime>
    <BeginTime>11:00 AM</BeginTime>
        <Location>Apartment</Location>
    <State>FL</State>
    <Street>123 Biscanye Blvd.</Street>
        <City>Miami</City>
    <TimeZone>EST</TimeZone>
</Event>
<Event>
    <AirDateTime>10/25/2003</AirDateTime>
    <ArriveTime>10:30 AM</ArriveTime>
    <BeginTime>11:00 AM</BeginTime>
        <Location>House</Location>
    <State>FL</State>
    <Street>123 Biscanye Blvd.</Street>
        <City>Miami</City>
    <TimeZone>EST</TimeZone>
</Event>
What I would like to do is match all Events that have the same AirDateTime and display the date with the location. Then go through again and show each with more detail. Below I have included a sample of what I'm looking for.

10/24/2003 - House
10/24/2003 - Apartment

10/25/2003 - House
~~~~~~~~~~~~~~~~~~~~~~~~~
10/24/2003 - 10:00AM
House
123 Biscanye Blvd.
Miami, FL

10/24/2003 - 10:30AM
Apartment
123 Biscanye Blvd.
Miami, FL

10/25/2003 - 10:00AM
House
123 Biscanye Blvd.
Miami, FL


Any help is appreciated, Please keep in mind that the XML events will not be presorted, dates will be jumbled up.

Thank you
Pete

Reply With Quote
  #2 (permalink)  
Old October 27th, 2003, 11:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Looks like just a straightforward sorting problem. Take a look at this stylesheet which applies the same sort twice - once for the summary and once for the detail. (Note that I had to add an <Events> container node to the XML you posted to make it a valid XML document, and that is reflected in the path used in the xsl:for-each).

Also, it would be easier to see that the sort is working correctly if you didn't have the same address in each Event ;)

Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:template match="/">
    <html>
      <head>
        <title>Events</title>
      </head>
      <body>

        <xsl:for-each select="Events/Event">
          <xsl:sort select="AirDateTime"/>
          <xsl:sort select="ArriveTime"/>
          <xsl:value-of select="AirDateTime"/> - <xsl:value-of select="Location"/>
          <br/>
        </xsl:for-each>
        <br/>
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        <br/><br/>

        <xsl:for-each select="Events/Event">
          <xsl:sort select="AirDateTime"/>
          <xsl:sort select="ArriveTime"/>
          <xsl:value-of select="AirDateTime"/> - <xsl:value-of select="ArriveTime"/>
          <br/>
          <xsl:value-of select="Location"/>
          <br/>
          <xsl:value-of select="Street"/>
          <br/>
          <xsl:value-of select="City"/>, <xsl:value-of select="State"/>
          <br/>
          <br/>
        </xsl:for-each>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
hth
Phil
Reply With Quote
  #3 (permalink)  
Old October 27th, 2003, 11:34 AM
Authorized User
 
Join Date: Oct 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you so much....

Seeing it like you have laid it out makes a lot of sense. I tested it and it works exactly like I hoped!

Thank you
Peter

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 member XSLT 25 July 13th, 2007 08:44 AM
SORTING pallone XSLT 3 October 29th, 2006 08:45 AM
Sorting sunny76 Excel VBA 2 September 19th, 2005 09:31 PM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM
Need help Sorting athanatos XSLT 5 August 11th, 2003 07:51 PM



All times are GMT -4. The time now is 01:58 AM.


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