tags:

views:

35

answers:

2

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/&lt;/url&gt;
      <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>
+3  A: 

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>
Tomalak
Thanks...that did the trick
AdRock
A: 

Here is the error message

Error loading stylesheet: Parsing an XSLT stylesheet failed.

Here is my XSL stylesheet cut down a bit

<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="festival/event/datefrom" data-type="text" order="ascending"/>

                    <div class="userdiv">

                        <xsl:call-template name="member_userid">
                            <xsl:with-param name="myid" select="user/@id" />
                        </xsl:call-template>

                        <xsl:call-template name="member_username">
                            <xsl:with-param name="myuser" select="user/account/username" />
                        </xsl:call-template>

                        <xsl:call-template name="member_name">
                            <xsl:with-param name="myname" select="user/personal/name" />
                        </xsl:call-template>



                    </div>
                </xsl:if>
            </xsl:for-each>
            <xsl:if test="position()=last()">
                <div class="count"><h2>Total number of festival organisers: <xsl:value-of select="count(/folktask/member/user/account/userlevel[text()=3])"/></h2></div>
                <div class="count"><h2>Total number of festivals: <xsl:value-of select="count(/folktask/member/festival)"/></h2></div>
            </xsl:if>
        </body>
    </html>
</xsl:template>
</xsl:stylesheet>

And here is an excerpt of the xml

<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="userfestival.xsl"?>
<folktask xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xs:noNamespaceSchemaLocation="folktask.xsd">
    <member>
        <festival id="1">
            <event>
                <eventname>Oxford Folk Festival</eventname>
                <url>http://www.oxfordfolkfestival.com/&lt;/url&gt;
                <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>
            <contact>
                <conname>Stuart Vincent</conname>
                <conaddress1>P.O. Box 642</conaddress1>
                <conaddress2></conaddress2>
                <concity>Oxford</concity>
                <concounty>Bedfordshire</concounty>
                <conpostcode>OX1 3BY</conpostcode>
                <contelephone>01865 79073</contelephone>
                <conmobile></conmobile>
                <fax></fax>
                <conemail>[email protected]</conemail>
            </contact>
        </festival>
    </member>
AdRock
Point 1) Stack Overflow is not a forum. Please post additions to your question, not to the "Answers" area. Point 2) It says "Parsing an XSLT stylesheet failed.", this means you've made syntax error somewhere. And this means "cutting down" the XSLT stylesheet a bit is *clearly* the wrong thing to do, since nobody can tell you about syntax errors in bits you have cut out. Point 3) Apparently this whole thing still has nothing whatsoever to do with sorting. Get your XSLT syntax straight, and after it stops complaining about parser errors you can look if sorting works.
Tomalak