[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Processing and sorting non-military time

Subject: RE: Processing and sorting non-military time
From: christoph.naber@xxxxxxxxxxxxxxxxxxx
Date: Fri, 17 Aug 2007 15:26:18 +0200
RE:  Processing and sorting non-military time
Some little typo caused the problem that the keys didn't work. Here is the
corrected stylesheet, should work right away...

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="yes"/>

  <!-- should select all events for a given date -->
  <xsl:key name="events-by-date" match="event"
use="substring(occurrences/occurrence/start,1,10)" />

  <!-- should only select the events where
substring(occurrences/occurence/start, 12, 2) != '12' -->
  <xsl:key name="events-by-date-main"
match="event[not(substring(occurrences/occurrence/start/text(), 12, 2) =
'12')]" use="substring(occurrences/occurrence/start,1,10)" />

  <!-- should only select the events where
substring(occurrences/occurrence/start, 12, 2) == '12' and
substring(occurrences/occurence/start, 18, 2) == 'AM'-->
  <xsl:key name="events-by-date-12am"
match="event[(substring(occurrences/occurrence/start/text(), 18, 2) =
'AM') and (substring(occurrences/occurrence/start/text(), 12, 2) = '12')]"
use="substring(occurrences/occurrence/start,1,10)" />

  <!-- should only select the events where
substring(occurrences/occurence/start, 12, 2) == '12' and
substring(occurrences/occurence/start, 18, 2) == 'PM'-->
  <xsl:key name="events-by-date-12pm"
match="event[(substring(occurrences/occurrence/start/text(), 18, 2) =
'PM') and (substring(occurrences/occurrence/start/text(), 12, 2) = '12')]"
use="substring(occurrences/occurrence/start,1,10)" />

  <xsl:template match="events">
    <root>
      <xsl:apply-templates select="event[count(. | key('events-by-date',
substring(occurrences/occurrence/start,1,10))[1]) = 1]">
        <xsl:sort select="substring(occurrences/occurrence/start,1,10)" />
      </xsl:apply-templates>
    </root>
  </xsl:template>

  <!-- this template should process all events with the same date as the
current event -->
  <xsl:template match="event" >

    <xsl:comment>selected by 12pm</xsl:comment>
    <xsl:apply-templates select="key('events-by-date-12pm',
substring(occurrences/occurrence/start,1,10))" mode="sorted">
      <xsl:sort select="substring(occurrences/occurrence/start,15,2)" />
    </xsl:apply-templates>

    <xsl:comment>selected by main</xsl:comment>
    <xsl:apply-templates select="key('events-by-date-main',
substring(occurrences/occurrence/start,1,10))" mode="sorted">
      <xsl:sort order="ascending"
select="substring(occurrences/occurrence/start,18,2)" />
      <xsl:sort order="ascending"
select="substring(occurrences/occurrence/start,12,2)" />
      <xsl:sort order="ascending"
select="substring(occurrences/occurrence/start,15,2)" />
    </xsl:apply-templates>

    <xsl:comment>selected by 12am</xsl:comment>
    <xsl:apply-templates select="key('events-by-date-12am',
substring(occurrences/occurrence/start,1,10))" mode="sorted">
      <xsl:sort order="ascending"
select="substring(occurrences/occurrence/start,15,2)" />
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="event" mode="sorted">
    <!-- ... -->
  </xsl:template>

</xsl:stylesheet>


Hope this helps
Christoph


If you are not the intended addressee, please inform us immediately that you
have received this e-mail by mistake and delete it. We thank you for your
support.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.