3 Replies Latest reply: Aug 19, 2008 2:21 PM by kf420 RSS

    SPRY: filter XML data by date

    Phil_W Community Member
      Hi,

      I have an XML data set that contains information on events for my mountaineering club. What I'd like to do is have the web page automatically filter the data so that only events that have a start date greater or equal to today are displayed. The reason for this is that we don't wish to have to load up a new XML dataset, removing the old events every time an event date passes.

      I have got this working using an XSL stylesheet transform. But it only works in Internet Explorer. (The extended functions I created do not work in the other browsers). You can see the results of this here.

      xml version

      with the stylesheet doing the transform being events2.xsl

      I've tried doing this with spry and the results are now also compatible with mozilla and opera browsers which is a great improvement.

      What I'm not clear on is the syntax in Spry / Javascript that I need for the filter I need to apply

      The spry version without filtering is here

      html spry version

      The xml looks as follows with Events being the repeating node, with child nodes describing the event data

      ?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet href="events2.xsl" type="text/xsl"?>
      <dataroot xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="Events.xsd" generated="2008-07-06T20:57:34">
      <Events>
      <ID>1</ID>
      <Title>Phasels Wood</Title>
      <Start_x0020_Date>2008-07-05</Start_x0020_Date>
      <End_x0020_Date>2008-07-05</End_x0020_Date>
      <Contact>Paul Dormer</Contact>
      <Details>Family weekend, all welcome. Camping on the Saturday night. Evening BBQ, climbing, fun and games for all the family.</Details>
      <Email>pdormer@fs.net</Email>
      <Link> http://www.phaselswood.org.uk</Link>
      </Events>
      <Events>
      <ID>2</ID>
      <Title>Bregalia Alps</Title>
      <Start_x0020_Date>2008-07-18</Start_x0020_Date>
      <End_x0020_Date>2008-08-03</End_x0020_Date>
      <Contact>Gary Bebb</Contact>
      <Details>This years Alps trip will be to the Bernina and Bregaglia Alps. There are lots of options for rock climbing, high level/low level and multi day walks, alpine climbing, cragging, mountain biking, sightseeing and water sports. Camping.</Details>
      <Email>garyHMC@hotmail.co.uk</Email>
      <Link> http://en.wikipedia.org/wiki/Bregaglia_Range</Link>
      </Events>
      <Events>

      What I would like to do is filter the events nodes returned based on the <Start_x0020_Date> node being greater than or equal to the current date. I have already written the javascript bit to return the current date in format yyyy-mm-dd, as I needed this for the XSL transform version.

      So what syntax do I need to achieve this? I'm new to Javascript and Spry and I'm sure this can't be that hard. I presume the format is some form of XPath statement but not the same format as per XSL?

      Help greatly appreciated

      Cheers

      Phil