Chrome 是否使用 XPath 2.0? [英] Does Chrome use XPath 2.0?
问题描述
我的印象是所有最新的浏览器现在都使用 XPath 2.当我使用 lower-case()
和 uppser-case()
(版本 2 中引入的函数)时,Chrome 会引发语法错误.但是,他们较旧的替代 translate()
工作正常.
I was under impression that all latest browsers are with XPath 2 now. When I use lower-case()
and uppser-case()
(functions introduced in version 2) Chrome throws a syntax error. However, their older alternative translate()
works fine.
这是一个错误还是最新的 Chrome 确实使用了 XPath 1?有没有找到 XPath 版本的命令/方法?
Is this a bug or does the latest Chrome actually use XPath 1? Is there a command / way to find out the XPath version?
// Finds the element as expected.
$x('//h2/text()[. = "Delete"]')
// Doesn't find the element (also expected).
$x('//h2/text()[. = "delete"]')
// SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//h2/text()[lower-case(.) = "delete"]' is not a valid XPath expression.
$x('//h2/text()[lower-case(.) = "delete"]')
推荐答案
不,Chrome 使用 XPath 1.0.
您可以将 XPath 表达式简化为 v2.0 函数来查看:
You can simplify your XPath expression to just a v2.0 function to see this:
$x("lower-case('ABC')")
SyntaxError: Failed to execute 'evaluate' on 'Document': The string 'lower-case('ABC')' is not a valid XPath expression.
尝试任何其他 XPath 2.0 函数,例如 current-date()
都会产生类似的错误.
Trying any other XPath 2.0 function such as current-date()
will yield a similar error.
除了此类探测之外,没有内置方法可以明确确定 XPath 实现的版本.
另一方面,XSLT 有 system-property('xsl:version')
用于确定版本 1.0 还是 2.0.
XSLT, on the other hand, has system-property('xsl:version')
for determining version 1.0 versus 2.0.
这篇关于Chrome 是否使用 XPath 2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!