排除晚于当天日期的项目 [英] Exclude items who has a later date than the date of today

查看:171
本文介绍了排除晚于当天日期的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于XSLT的问题。

I have a question about XSLT.

在网站上,我有一个简单的日历,显示将来发生的事件。

On a website i have a simple calendar, showing events who are going on in the future.

但事件完成后,应从我的列表中删除。事实上,我的意思是事件发生的日期是今天的日期。

But when an event is done, it should be removed from my list. By done i mean, that the date of the event is past the date of today.

每个事件都附有日期。

查看以下代码:

<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>

上面的代码将显示一个template ='1238'的所有事件,这也是正确的,因为这是我的事件的模板。

The above code will show me all events with a template='1238' and that is also correct, because that is the template of my events.

但正如我之前提到的,每个事件都有一个包含日期的字段。该字段称为dato。这也是我在以后排序事件的数字,所以日期最接近今天的事件将显示在列表的顶部。

But as I mentioned before every event have a field containing a date. The field is called "dato". This is also the number I am sorting the events after, so the event with a date closest to today will be shown at the top of the list.

dato-field是:2009-08-30T08:59:00

The format of the "dato"-field is: 2009-08-30T08:59:00

我如何自动删除date字段的值过去的事件今天的日期?

How do i automaticaly remove an event where the value of the "date"-field is past the date of today?

所以如果今天的日期是:2009年9月3日,2009年8月30日的事件不应该列在名单上。 / p>

So if todays date is: 3th of september 2009, an event who has a date of 30th of august 2009 should not figure on the list.

推荐答案

假设您使用XSLT 1.0,如果您的XSLT处理器支持EXSLT扩展,则可以使用日期:差异功能。还有一个可以使用的简单XSLT模板,您可以根据自己的情况适应您的情况,以防您无法使用EXSLT。

Assuming that you are using XSLT 1.0, If your XSLT processor supports the EXSLT extensions, you could make use of the date:difference function. There is also a plain XSLT template that is available which you can adapt to your scenario in case you do not have EXSLT natively available.

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

编辑:

可能还有一个更简单的版本,您可以将日期时间字符串转换为具有格式为YYYYMMDDHHMMSS。这将自动以数字升序排列(未来的日期/时间将比以前的日期更大),然后您可以以相同的方式获取当天的日期时间字符串,并进行常规的数字差异,以查看是否为是在当前日期之前或之前。

There could be another simpler version where you convert your date-time-string to become a number having the format YYYYMMDDHHMMSS. This will be ordered in numerically ascending order automatically(future dates/times will have a bigger number than previous dates), you could then take the current day's date-time string in the same way and do a regular numeric 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

在您的XPath中,您可以这样做,假设$ currDateTime设置为正确的翻译值,< data> 节点具有要检查的日期,您可以使用以下..

In your XPath, you can do this, assuming $currDateTime is set to the right translated value and the <data> node has the date to check, you could use the below..

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

这篇关于排除晚于当天日期的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆