假设我有一个包含属性日期时间的节点列表,并且我只想选择 $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 中选择我会做的日期范围内的项目
/records/record[xs:dateTime(@datetime) > xs:dateTime($compare-datetime)]
然而,在 XSLT 1.0 中,我尝试了很多不同的方法并大量寻找答案,但没有成功。
我开始认为,除了将实际的 dateTime 解析为整数值之外,这在 xslt 中并不是一个简单的任务。
我希望有人能给我一个明确的答案,这样我至少可以知道我面临的是什么。
干杯,
凯西
最佳答案
如果日期始终位于同一时区,并且具有固定宽度字段(每个字段中的位数恒定),我相信您可以采用 this approach :去掉标点符号,留下数字,然后比较数字。
<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 按日期范围选择节点。这可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4618115/