How to sort XML file by date in XLST

I am trying to sort by date and get an error that the stylesheet cannot be loaded

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

This is where it should be sorted. The recorded string is where the sort should happen

<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"/>-->

      

Example 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>

      

+2


a source to share


1 answer


There is no need to create complex string manipulations that turn <datefrom>

into a number. Dates in the format are yyyy-mm-dd

perfectly sorted as text.



<xsl:for-each select="folktask/member[user/account/userlevel='3']">
  <xsl:sort select="festival/event/datefrom" />
  <!-- ... -->
</xsl:for-each>

      

+3


a source







All Articles