This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: XSL month sorting (chronologically)
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "murli bk" <bkmurali at hotmail dot com>
- Cc: XSL-List at lists dot mulberrytech dot com
- Date: Thu, 11 Apr 2002 13:54:38 +0100
- Subject: Re: [xsl] XSL month sorting (chronologically)
- Organization: Jeni Tennison Consulting Ltd
- References: <F48r3gIa7ZhZFBbCA6T00007868@hotmail.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Murali,
> I want to sort on the date in chronological order(with the month
> field in letters).
Ahh, well that makes more sense, and is correspondingly more difficult.
I think that the easiest way to do it is to create a document that
holds the months in the correct order:
--- months.xml ---
<?xml version="1.0"?>
<months>
<month>Jan</month>
<month>Feb</month>
<month>Mar</month>
...
</months>
---
You can then iterate over the months by iterating over the month
elements from this document:
<xsl:template match="eventlog">
<xsl:variable name="events" select="event" />
<xsl:for-each select="document('months.xml')/months/month">
<xsl:variable name="month" select="." />
...
</xsl:for-each>
</xsl:template>
Then you can find the events that occur in that particular month, and
iterate over those, sorting by their day:
<xsl:template match="eventlog">
<xsl:variable name="events" select="event" />
<xsl:for-each select="document('months.xml')/months/month">
<xsl:variable name="month" select="." />
<xsl:for-each select="$events[substring(date, 4, 3) = $month]">
<xsl:sort select="substring(date, 1, 2)" data-type="number" />
<xsl:value-of select="date" />
<xsl:text>, </xsl:text>
<xsl:value-of select="data" />
</xsl:for-each>
</xsl:for-each>
</xsl:template>
If there are lots of events, you should set up a key that indexes the
events by the month in which they occurred to make things quicker.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list