How to sort an XML file by date in XLST

Posted by AdRock on Stack Overflow See other posts from Stack Overflow or by AdRock
Published on 2010-04-21T12:04:25Z Indexed on 2010/04/21 12:23 UTC
Read the original article Hit count: 273

Filed under:

I am trying to sort by date and get an error message about the stylesheet can't be loaded

I found an answer on how others have suggested but it doesn't work for me

Here is where it is supposed to sort. The commented out line is where the sort should occur

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

 <xsl:template name="hoo" match="/">
  <html>
   <head>
    <title>Registered Festival Organisers and Festivals</title>
    <link rel="stylesheet" type="text/css" href="userfestival.css" />
   </head>
   <body>
    <h1>Registered Festival Organisers and Festivals</h1>

    <xsl:for-each select="folktask/member">

     <xsl:if test="user/account/userlevel='3'">
      <!--<xsl:sort select="concat(substring(festival/event/datefrom,1,4),substring(festival/event/datefrom, 6,2),substring(festival/event/datefrom, 9,2))" data-type="number" order="ascending"/>-->

Sample node from XML

    <festival id="1">
     <event>
      <eventname>Oxford Folk Festival</eventname>
      <url>http://www.oxfordfolkfestival.com/</url>
      <datefrom>2010-04-07</datefrom>
      <dateto>2010-04-09</dateto>
      <location>Oxford</location>
      <eventpostcode>OX1 9BE</eventpostcode>
      <coords>
       <lat>51.735640</lat>
       <lng>-1.276136</lng>
      </coords>
     </event>
    </festival>

© Stack Overflow or respective owner

Related posts about xslt