Sort by Date in XSLT
Sometimes the simple things are more difficult than they should be. Take sorting XML records by date through an XSLT stylesheet. Nothing is built in to handle this basic function. So when left to our own devices, we have to break up the date into substrings and compare each piece of the puzzle. In the code below, we are sifting through a date formatted like ’11/17/2009′. To get the year, we start with the 7th character then take the next 4. We evaluate our year, our month then the day and this sorts the dates in ascending order. If we wanted to have these in descending, we’d add the order=”descending” parameter to the xsl:sort.
