The date format that you chose allows for sorting the value as text.
Input XML:
<events>
<event>
<date>2004-02-12</date>
</event>
<event>
<date>2003-02-15</date>
</event>
<event>
<date>2004-03-01</date>
</event>
<event>
<date>2001-02-11</date>
</event>
<event>
<date>2004-11-15</date>
</event>
</events>
The XSL template:
<!-- match the root of the document -->
<xsl:template match="/">
<!-- output sorted_events element -->
<sorted_events>
<!-- Iterate over all events/event nodes -->
<xsl:for-each select="events/event">
<!-- sort the nodes by text value of the events/event/date node -->
<xsl:sort select="date" data-type="text" order="ascending"/>
<!-- copy of the event node to the output -->
<xsl:copy-of select="."/>
</xsl:for-each>
</sorted_events>
</xsl:template>
Output XML:
<sorted_events>
<event>
<date>2001-02-11</date>
</event>
<event>
<date>2003-02-15</date>
</event>
<event>
<date>2004-02-12</date>
</event>
<event>
<date>2004-03-01</date>
</event>
<event>
<date>2004-11-15</date>
</event>
</sorted_events>
Hope this helps,
Josh
-----Original Message-----
From: allan(_dot_)mccluskey(_at_)centrelink(_dot_)gov(_dot_)au
[mailto:allan(_dot_)mccluskey(_at_)centrelink(_dot_)gov(_dot_)au]
Sent: Tuesday, January 13, 2004 12:28 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Sorting different date formats
Hi all,
Could someone please show me how to perform and XSL:SORT on an date in this
format? <endDate>2004-02-15</endDate>
I have many other sorts that I need to perform so an explantion would also
be much appreciated so I can fully understand how you do it : )
Many thanks,
Allan
Important: This e-mail is intended for the use of the addressee and may
contain information that is confidential, commercially valuable or subject to
legal or parliamentary privilege. If you are not the intended recipient you
are notified that any review, re-transmission, disclosure, use or dissemination
of this communication is strictly prohibited by several Commonwealth Acts of
Parliament. If you have received this communication in error please notify the
sender immediately and delete all copies of this transmission together with any
attachments.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list