This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: XSL month sorting (chronologically)


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]