SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2011
    0 Post(s)
    0 Thread(s)

    Sorting by date in xsl file?

    I'm getting a date feed which has a format "11/18/2011 12:00:00 PM" or "3/1/2011 10:00:00 AM". As you can see in the format there are no leading zeros for the date.

    How do I sort by date with this format?

    This is what I have so far

    <xsl:stylesheet xmlns:xsl="" version="1.0">
    <xsl:param name="sortBy" select="'StartDate"/>
    <xsl:param name="strXPath" select="//Activity"/>
    <xsl:template match="/">    
      <xsl:apply-templates select="$strXPath">
        <xsl:sort select="*[name()=$sortBy]" order="ascending"/>
    <xsl:template match="Activity">
       <td><xsl:value-of select="ActivityStartDateTime"/></td>
       <td><xsl:value-of select="Name"/></td>
    Right now it is sorting by String. "11/13/2011 12:00:00 AM" comes before "2/25/2011 12:00:00 AM". I trying to get "2/25/2011 12:00:00 AM" before "11/13/2011 12:00:00 AM"

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Washington, DC
    4 Post(s)
    0 Thread(s)
    Welcome to a special form of hell.

    XSL doesn't have a concept of datatypes in a conventional sense. Best bet would be to output the datetime values in a sortable manner if possible. The few times I've had to do this we actually spit out several datetimes -- one for sorting (unix timestamp), one short display and one long dispalay. Extra fields beat the hell out of figuring out how to do it in XSL.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts