开发者

How to sort an XML file by date in XLST

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/dat开发者_运维问答efrom, 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>


There is no need to make complicated string manipulations that turn <datefrom> into a number. Dates in the yyyy-mm-dd format sort perfectly well as text.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜