比较XPath 1.0中的两个TimeStrings?

时间:2014-07-08 11:38:58

标签: xpath xpath-1.0

如何在XPath1.0中比较这些字符串:

08-jul-2014 05:00:00
08-jul-2014 06:00:00

例如:

08-jul-2014 05:00:00 > 08-jul-2014 06:00:00应该返回false

08-jul-2014 05:00:00 < 08-jul-2014 06:00:00应该返回true

我查看了Xpath构建的函数,我找不到任何将字符串转换为UTC秒的函数,例如......

提前致谢!

1 个答案:

答案 0 :(得分:1)

您可以使用以下黑客攻击。使用translate()删除分隔符并使用substring()将其格式化为yyyyMMddHHmmss,然后比较此暴行。

article[number(substring(translate(translate(translate(@pub-date,'-',''),':',''),' ','') ,5,4)+substring(translate(translate(translate(@pub-date,'-',''),':',''),' ',''),2,3)+substring(translate(translate(translate(@pub-date,'-',''),':',''),' ',''),0,2)+substring(translate(translate(translate(@pub-date,'-',''),':',''),' ',''),9,6)) > number(substring(translate(translate(translate(@pub-date2,'-',''),':',''),' ','') ,5,4)+substring(translate(translate(translate(@pub-date2,'-',''),':',''),' ',''),2,3)+substring(translate(translate(translate(@pub-date2,'-',''),':',''),' ',''),0,2)+substring(translate(translate(translate(@pub-date2,'-',''),':',''),' ',''),9,6))]

我刚才意识到,因为你有月份作为字符串,所以你已经填满了。