XSLT1.0/XPath 1.0 按日期范围选择节点.这甚至可能吗? [英] XSLT1.0/XPath 1.0 Selecting nodes by date range. Is this even possible?

查看:22
本文介绍了XSLT1.0/XPath 1.0 按日期范围选择节点.这甚至可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个包含属性 datetime 的节点列表,我只想选择 $compare-datetime 之后发生的记录.

Lets say I have a list of nodes that contain an attribute datetime, and I want to select only the records that occur after $compare-datetime.

<records>
    <record @datetime="2010-01-04T16:48:15.501-05:00"/>
    <record @datetime="2010-01-03T16:48:15.501-05:00"/>
    ...etc...
</records>

在 xquery 中选择我会做的日期范围内的项目

In xquery to select items within a date range I would do

/records/record[xs:dateTime(@datetime) > xs:dateTime($compare-datetime)]

但是在 XSLT 1.0 中,我尝试了很多不同的方法并寻找了很多答案,但都没有成功.

However in XSLT 1.0 I have tried alot of different approaches and alot of searching for answers, without any luck at getting this to work.

我开始认为除了将实际 dateTime 解析为整数值之外,这在 xslt 中不是一项简单的任务.

I am beginning to think that short of parsing the actual dateTime to an integer value, this is not a simple task in xslt.

我希望有人能给我一个明确的答案,这样我至少可以知道我要面对的是什么.

I am hoping someone can give me a definite answer on that so I can at least know what I am up against.

干杯,

凯西

推荐答案

如果日期总是在同一个时区,并且有固定宽度的字段(每个字段的位数固定),我相信你可以这种方法:去掉标点符号,留下数字,然后比较数字.

If the dates will always be in the same time zone, and have fixed-width fields (constant number of digits in each field), I believe you could take this approach: remove punctuation, leaving the numbers, and compare the numbers.

<xsl:variable name="datetime-punctuation" select="'-.:T'" />
<xsl:variable name="stripped-compare-datetime"
  select="number(translate($compare-datetime, $datetime-punctuation, ''))" />

然后使用

/records/record[number(translate(@datetime, $datetime-punctuation, ''))
                 > $stripped-compare-datetime)]

这篇关于XSLT1.0/XPath 1.0 按日期范围选择节点.这甚至可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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