tags:

views:

214

answers:

2

Hello

I would like to sort a list of 1500 files in XSLT 1. The list is similar to:

01052003.xls -> (translate to: 1th of May 2003)
25062004.xls -> (translate to: 25th of June 2004)
31032001.xls -> (translate to: 31th of Marts 2001)

I can do a sort by name but since they are named ddmmyyyy sorting will be wrong.

Can I somehow sort files by this strange date?

Alternatively I will have to find a tool that can rename many files in a folder based on a regex...

Br. Anders

+4  A: 

Using the xsl:sort instruction you can combine multiple sort keys based on substrings. A good example is linked below:

http://www.xml.com/pub/a/2002/07/03/transform.html

...it's easy enough to have three sort keys based on the year, month, and day substrings of the date string:

<xsl:template match="employees">
  <xsl:apply-templates>
    <xsl:sort select="substring(@hireDate,7,4)"/><!-- year  -->
    <xsl:sort select="substring(@hireDate,1,2)"/><!-- month -->
    <xsl:sort select="substring(@hireDate,3,2)"/><!-- day   -->
  </xsl:apply-templates>
</xsl:template>
Jim
Thanks. Did not know multible sort where allowed. That will do the trick.
Tillebeck
+1  A: 

What about reverse it?

<xsl:for-each select="dates/date">
    <xsl:sort select="substring(., 5, 4)" />
    <xsl:sort select="substring(., 3, 2)" />
    <xsl:sort select="substring(., 1, 2)" />
    <xsl:value-of select="." /><br />
</xsl:for-each>
Rubens Farias
+1 - AFAICS, your solution is correct. The accepted one isn't.
Tomalak