Re: [xsl] Sorting by date

Subject: Re: [xsl] Sorting by date
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 27 May 2008 18:03:14 +0200
sudheshna iyer wrote:
I am using xsl:stylesheet version="1.0".

Here is an XSLT 1.0 stylesheet that produces the result you described. You only need to complete the "translation table" for the months:


<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  xmlns:dt="http://example.com/2008/data";
  version="1.0">

<xsl:output method="text"/>

  <data xmlns="http://example.com/2008/data";>
    <month s="Jan" n="01"/>
    <month s="Feb" n="02"/>
    <month s="Mar" n="03"/>
    <month s="Apr" n="04"/>
    <!-- add other months here -->
  </data>

<xsl:template match="/">
<xsl:apply-templates select="rss/channel/item">
<xsl:sort data-type="number" order="descending"
select="concat(substring(SortDate, 13, 4), document('')/xsl:stylesheet/dt:data/dt:month[@s = substring(current()/SortDate, 9, 3)]/@n, substring(SortDate, 6, 2))"/>
</xsl:apply-templates>
</xsl:template>


<xsl:template match="item">
<xsl:value-of select="concat(substring(SortDate, 13, 4), '-', document('')/xsl:stylesheet/dt:data/dt:month[@s = substring(current()/SortDate, 9, 3)]/@n, '-', substring(SortDate, 6, 2), '&#10;', title, '&#10;&#10;')"/>
</xsl:template>


</xsl:stylesheet>


--


	Martin Honnen
	http://JavaScript.FAQTs.com/

Current Thread