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 October 27th, 2003, 10:23 AM
Authorized User
 
Join Date: Oct 2003
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

 
Old October 27th, 2003, 11:06 AM
Friend of Wrox
 
Join Date: Jun 2003
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
 
Old October 27th, 2003, 11:34 AM
Authorized User
 
Join Date: Oct 2003
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






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





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