[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

XSL Sort Date

Posted on 2007-08-02
4
Medium Priority
?
225 Views
Last Modified: 2013-11-18
This is an XSL Question ...
Does anyone know how to sort date items of the format DD MMM YYYY (05 Jul 2007, 22 Oct 2006).
Thanks
0
Comment
Question by:simshp
  • 3
4 Comments
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19618145
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 1000 total points
ID: 19618265
in your case that would be something like this

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:map="gbs:map" exclude-result-prefixes="map" version="1.0">
    <xsl:template match="/">
        <xsl:for-each select="//date">
            <xsl:sort select="substring(., 8)" data-type="number" order="ascending" />
            <xsl:sort select="document('')//map:item[@val=substring(., 4,2)]/@order" data-type="number" order="ascending"/>
            <xsl:sort select="substring(., 1,2)" data-type="number" order="ascending" />
            <xsl:value-of select="."/>
        </xsl:for-each>
    </xsl:template>
    <map:item val="Jan" order="01"/>
    <map:item val="Feb" order="02"/>
    <map:item val="Mar" order="03"/>
     ...
 </xsl:stylesheet>

Of course you need to enable the document() function if your processor disables that by default

You could convert to a date like this YYYY-MM-DD using the exslt date templates (www.exslt.org)
but I find this lookup table way a lot less coding

cheers

Geert

0
 

Author Comment

by:simshp
ID: 19618578
Thanks .. that seems to work well !
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 19618891
welcome
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question