Chrome是否使用XPath 2.0? [英] Does Chrome use XPath 2.0?
问题描述
我的印象是,现在所有最新的浏览器都使用XPath 2。当我使用小写()
和 uppser-case()
(版本2中引入的函数)时,Chrome会抛出语法错误。然而,他们较旧的替代方案 translate()
可以正常工作。
这是一个错误还是最新的Chrome实际使用XPath 1?有没有找到XPath版本的命令/方法?
//找到预期的元素。
$ x('// h2 / text()[。=Delete]')
//找不到元素(也是预期的)。
$ x('// h2 / text()[。=delete]')
// SyntaxError:无法在'Document'上执行'evaluate':字符串' // h2 / text()[小写(。)=delete]'不是有效的XPath表达式。
$ x('// h2 / text()[lower-case(。)=delete]')
$ b $ Chrome浏览器使用XPath 1.0。
您可以简化你的XPath表达式只有v2.0函数才能看到:
$ x(小写('ABC') )
SyntaxError:无法对'Document'执行'evaluate':字符串'小写'('ABC')'不是有效的XPath表达式。
尝试使用其他XPath 2.0函数(如 current-date() code>会产生类似的错误。
没有内置的方式来确定XPath实现的版本,而不是通过这些探测器。
另一方面,XSLT具有系统属性('xsl:version')
确定版本1.0与2.0。
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.
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"]')
No, Chrome uses XPath 1.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.
Trying any other XPath 2.0 function such as current-date()
will yield a similar error.
There is no built-in way of definitively determining the version of an XPath implementation other than by such probes.
XSLT, on the other hand, has system-property('xsl:version')
for determining version 1.0 versus 2.0.
这篇关于Chrome是否使用XPath 2.0?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!