tags:

views:

110

answers:

2

I have an RSS of an events feed. I would like to hide previous events.

Assuming XML data subset of

<Navigation Name="ItemList" Type="Children">
<Page ID="x32444" URL="..." Title="Class..."
EventStartDate="20090831T23:00:00" EventEndDate="20090904T23:00:00"
  EventStartTime="20090830T15:30:00" EventEndTime="20090830T18:30:00" Changed="20090830T20:28:31" CategoryIds="" Schema="Event"
  Name="Class of 2010 BAKE SALE"/>
 <Page ID="x32443" URL="x32443.xml?Preview=true&Site=&UserAgent=&IncludeAllPages=true&tfrm=4" Title="Class of 2010 BAKE SALE"
  Abstract="Treat yourself with our famous 10-star FRIED ICE CREAM!" EventStartDate="20090831T23:00:00" EventEndDate="20090904T23:00:00"
  EventStartTime="20090830T15:30:00" EventEndTime="20090830T18:30:00" Changed="20090830T20:25:35" CategoryIds="" Schema="Event"
  Name="Class of 2010 BAKE SALE"/>
 <Page ID="x32426" URL="x32426.xml?Preview=true&Site=&UserAgent=&IncludeAllPages=true&tfrm=4" Title="Tribute to ..."
  Abstract="Event to recognize and celebrate the lifetime of leadership and service ..."
  EventStartDate="20091206T00:00:00" EventEndDate="20091206T00:00:00" EventStartTime="20090828T23:00:00" EventEndTime="20090828T04:00:00"
  Changed="20090828T22:09:54" CategoryIds="" Schema="Event" Name="Tribute to ...."/>


</Navigation>

How would I not include anything past today's date

<xsl:apply-template select="Page[@EventStartDate=notBeforeToday()]"/>
A: 

Easiest with XSL parameters that you set from outside.

<xsl:param name="today" select="'undefined'" />

<!-- time passes... -->

<xsl:apply-templates select="Page[@EventStartDate &lt; $today]"/>

Your date format is such that you can compare it using string comparison, unless there are different timezones involved. You would simply set

20091001T00:00:00

as the param value for $today. Have a look into your XSLT processor's documentation to see how.

The alternative would be to use an extension function. Here it depends on which extension functions your XSLT processor supports, so this approach won't be portable.

Tomalak
A: 

For this purpose, i usually add an extra date attribute in the XML which contains the day number since year 1900.

for example @dateid='9876543' or @seconds="9876675446545"

then i can can easily compare with today or another variable in the XSL.

You can also use this technique to compare times using "Unix time" for example

jujule