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

Re: sorting by date

Subject: Re: sorting by date
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 23 Jan 2001 12:23:01 GMT
bash sort by date
You might want to consider using an extension function to a language
with built in date parsing, but if not....

restricted to outputting first 5 in oorder, and showing the sort key for
clarity:

<x>

<content id="66228-135831" displayText="banjo"  publicationDate="Wed Jan 01
00:00:00 GMT 1999" />
<content id="66228-135832" displayText="banjo"  publicationDate="Wed Aug 02
00:00:00 GMT 2001" />
<content id="66228-135833" displayText="banjo"  publicationDate="Wed Jul 03
00:00:00 GMT 2000" />
<content id="66228-135834" displayText="banjo"  publicationDate="Wed Jun 04
00:00:00 GMT 2000" />
<content id="66228-135835" displayText="banjo"  publicationDate="Wed May 05
00:00:00 GMT 1999" />
<content id="66228-135836" displayText="banjo"  publicationDate="Wed Apr 06
00:00:00 GMT 2000" />
<content id="66228-135840" displayText="banjo"  publicationDate="Wed Mar 07
00:00:00 GMT 2001" />
<content id="66228-135889" displayText="banjo"  publicationDate="Wed Feb 08
00:00:00 GMT 1998" />
<content id="66228-135890" displayText="banjo"  publicationDate="Wed Jan 09
00:00:00 GMT 2000" />
<content id="66228-135618" displayText="lotus" strapline="lotus"
publicationDate="Wed Mar 02 00:00:00 GMT 2000" />
<content id="66228-135713" displayText="nother Test" strapline="asd"
publicationDate="Wed Dec 13 00:00:00 GMT 2000" />

</x>






<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0"
                xmlns:month="data:,month"
                >

<xsl:output method="xml" indent="yes"/>

<month:x m="Jan" pos="01" />
<month:x m="Feb" pos="02" />
<month:x m="Mar" pos="03" />
<month:x m="Apr" pos="04" />
<month:x m="May" pos="05" />
<month:x m="Jun" pos="06" />
<month:x m="Jul" pos="07" />
<month:x m="Aug" pos="08" />
<month:x m="Sep" pos="09" />
<month:x m="Oct" pos="10" />
<month:x m="Nov" pos="11" />
<month:x m="Dec" pos="12" />


<xsl:template match="x">
<xsl:for-each select="content">
<xsl:sort select="concat(substring(@publicationDate,25,4),
                   document('')//month:x
                    [@m=substring(current()/@publicationDate,5,3)]/@pos,
                   substring(@publicationDate,9,2))"/>

<xsl:if test="position() &lt; 5">
[<xsl:value-of select="concat(substring(@publicationDate,25,4),
                   document('')//month:x
                    [@m=substring(current()/@publicationDate,5,3)]/@pos,
                   substring(@publicationDate,9,2))"/>]
<xsl:copy-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>



bash-2.01$ xt date.xml date.xsl
<?xml version="1.0" encoding="utf-8"?>

[19980208]
<content id="66228-135889" displayText="banjo" publicationDate="Wed Feb 08 00:00:00 GMT 1998"/>
[19990101]
<content id="66228-135831" displayText="banjo" publicationDate="Wed Jan 01 00:00:00 GMT 1999"/>
[19990505]
<content id="66228-135835" displayText="banjo" publicationDate="Wed May 05 00:00:00 GMT 1999"/>
[20000109]
<content id="66228-135890" displayText="banjo" publicationDate="Wed Jan 09 00:00:00 GMT 2000"/>

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.