|
Subject: Re: [xsl] XSL month sorting (chronologically) From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Thu, 11 Apr 2002 13:54:38 +0100 |
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
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| [xsl] XSL month sorting (chronologi, murli bk | Thread | RE: [xsl] XSL month sorting (chrono, Michael Kay |
| RE: [xsl] Netscape XSLT ?, Elliotte Rusty Harol | Date | RE: [xsl] about data types, Michael Kay |
| Month |