Exclude items that are later than today's date

I have a question about XSLT.

On the website, I have a simple calendar showing events that happen in the future.

But when the event is done, it should be removed from my list. By the end, I mean that the date of the event has passed from today.

Each event has a date attached.

Take a look at the following code:

<xsl:for-each select="$currentPage//node[@template='1238']">

    <xsl:sort data-type="text" select="./data[@alias='dato']" order="ascending"/>

    <div class="aktivitet_forside">
            ...MY EVENT CONTENT...                    
    </div>

</xsl:for-each>

      

The above code will show me all events with pattern = '1238' and that is correct too, because this is my event pattern.

But as I said before, every event has a field containing a date. The field is called "dato". This is also the number in which I sort the events after that, so the event with the closest date to today will be shown at the top of the list.

Date field format: 2009-08-30T08: 59: 00

How can I automatically remove an event in which the value of the "date" field has passed since today?

So, if today's date is September 3, 2009, the event that is dated August 30, 2009 should not appear in the list.

+2


source to share


1 answer


Assuming you are using XSLT 1.0. If your XSLT processor supports EXSLT extensions, you can use the date: difference function. There is also a simple XSLT template available that you can adapt to your scenario if you don't have EXSLT available out of the box.

http://www.exslt.org/date/functions/difference/index.html

EDIT:

There may be another simpler version in which you convert your datetime string to a number that has the format YYYYMMDDHHMMSS. This will be ordered numerically in ascending order automatically (future dates / times will have a larger number than previous dates), you could take the datetime string of the current day in the same way and do a normal numerical difference to see if the day is after or before the current date.



<xsl:variable name="newFormat" select="translate('2009-08-30T08:59:00', '-T:', '')"/>

Gives 20090830085900

      

In your XPath, you can do this, assuming the $ currDateTime is set to the translated value on the right and <data>

node has the validation date, you can use below.

<xsl:for-each select="$currentPage//node[@template='1238'][data[@alias='dato' and ((number(translate(. ,'-T:', '')) - number($now)) &gt;=0)]]">

      

+2


source







All Articles