我正在尝试根据格式为日期的属性来过滤元素yyyy-MM-dd
.
我的 XML 看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<root>
<article title="wired" pub-date="2010-11-22" />
<article title="Plus 24" pub-date="2010-11-22" />
<article title="Finance" pub-date="2010-10-25" />
</root>
我的 xpath 尝试:
'//article[xs:date(./@pub-date) > xs:date("2010-11-15")]'
使用 xpath 2.0 - 除非绝对必要,否则将避免添加模式。
来自评论:
我相信我一定错过了什么
然后。我是否有可能需要
为 xs:date 指定其他内容
工作?也许是 xs: 命名空间
定义?
在 XPath 1.0 和 2.0 中您都可以使用:
//article[number(translate(@pub-date,'-','')) > 20101115]
你的XPath 2.0表达式是正确的,使用Saxon 9.0.3这个转换:
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="/">
<xsl:sequence select="//article[xs:date(./@pub-date) > xs:date('2010-11-15')]"/>
</xsl:template>
</xsl:stylesheet>
当应用于提供的 XML 文档时:
<root>
<article title="wired" pub-date="2010-11-22" />
<article title="Plus 24" pub-date="2010-11-22" />
<article title="Finance" pub-date="2010-10-25" />
</root>
产生想要的正确结果:
<article title="wired" pub-date="2010-11-22"/>
<article title="Plus 24" pub-date="2010-11-22"/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)