浏览器中的XPath 3 [英] XPath 3 in browser

查看:80
本文介绍了浏览器中的XPath 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们看到一致性图表时,例如 https://caniuse.com/#search=xpath https:// developer。 microsoft.com/en-us/microsoft-edge/platform/status/domlevel3xpath/?q=xpath ,通常与 DOM级别3 XPath ,其重点是使用XPath 1.0 来访问DOM对象,但不一定是XPath 3.0或

When we see conformance chart, such as https://caniuse.com/#search=xpath and https://developer.microsoft.com/en-us/microsoft-edge/platform/status/domlevel3xpath/?q=xpath, it's usually about DOM Level 3 XPath that focuses on accessing DOM object using XPath 1.0, but not necessarily XPath 3.0 or higher.

问题1-W3C等对浏览器是否有明确的版本要求,以支持较新版本的XPath?

Question 1 - Is there any explicit version requirement for browsers by W3C etc. to support newer versions of XPath?

此XPath 1.0功能有效:

This XPath 1.0 feature works:

document.evaluate(
  'normalize-space(" X  ")',
  document, null, XPathResult.ANY_TYPE, null ).stringValue

// => "X"

但这是XPath 3.0内联函数功能( ref )抛出:

But this XPath 3.0 inline-function feature (ref) throws:

document.evaluate(
  'let $incr := function($n as xs:integer) as xs:integer { $n +1 } return $incr(2)',
  document, null, XPathResult.ANY_TYPE, null ).stringValue

Edge:


XPATH15001:XPath查询 let $ incr:= function($ n as xs:integer)as xs:integer {$ n +1} return $ incr(2)不支持

XPATH15001: XPath query "let $incr := function($n as xs:integer) as xs:integer { $n +1 } return $incr(2)" not supported

Firefox:


SyntaxError:该表达式不是合法表达式。

SyntaxError: The expression is not a legal expression.

问题2-如果假设存在错误,是否允许浏览器使用XPath 3.0在我的代码中;那么v3.1功能(例如箭头功能)如何?

Question 2 - If XPath 3.0 is allowed in browser, assuming bug in my code; then how about v3.1 features (such as arrow-functions), are those also allowed?

推荐答案

没有浏览器原生支持XPath 2.0 ,更不用说XPath 3.0。

No browsers support XPath 2.0 natively, let alone XPath 3.0.

请注意,与XSLT不同,XPath除了确定给定版本支持的功能并观察是否发生错误外,没有确定XPath实现版本的内在方法 ,就像您一样。

Note also that XPath, unlike XSLT, doesn't have an intrinsic way of determining the version of an XPath implementation other than trying a function supported by a given version and observing whether an error occurs, as you've done.

这篇关于浏览器中的XPath 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆