This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: sorting by date
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] sorting by date
- From: David Carlisle <davidc at nag dot co dot uk>
- Date: Tue, 23 Jan 2001 12:23:01 GMT
- References: <8BD71A154EA6D211873E00105A125CDF5863EA@TSSMX1>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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() < 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