XSL Sort Date

Posted on 2007-08-02
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).
Question by:simshp
    LVL 60

    Expert Comment

    by:Geert Bormans
    LVL 60

    Accepted Solution

    in your case that would be something like this

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet xmlns:xsl=""
        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="."/>
        <map:item val="Jan" order="01"/>
        <map:item val="Feb" order="02"/>
        <map:item val="Mar" order="03"/>

    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 (
    but I find this lookup table way a lot less coding




    Author Comment

    Thanks .. that seems to work well !
    LVL 60

    Expert Comment

    by:Geert Bormans

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Most of the sites are being standardized with W3C Web Standards. W3C provides lot of web standard services to the web. They have the web specification, process and documentation for all the web standards. You can apply HTML, CSS and Accessibility st…
    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.
    Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
    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…

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now