简体   繁体   中英

What browsers support Xpath 2.0?

I have recently been working with XPath and have been searching for information on which browsers support XPath 2.0 without much luck. The best I could find was the query technologies comparison table of various rendering engines.

This clearly tells me that Firefox and IE (all versions of both) do not support XPath 2.0, but what about the other rendering engines for Chrome, Safari, etc.? Does anybody have any information on this or know where one can find it?

I do not know of any, and the official list of implementations doesn't include one either.

An alternative - of course less performant than a native implementation - would be XQIB which is an XQuery implementation in JavaScript. XPath 2.0 is fully included as a subset in XQuery 1.0, so you will be able to use all XPath 2.0 features (and more) in all browsers with JavaScript support.

A short sample taken from their website on how to use it:

<script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
<script type="application/xquery">
  b:alert(
    let $x := <a><b>2</b><c>4</c></a>
    return xs:string($x/b * $x/c)
  )
</script>

Majority of the browsers do not support XPATH 2.0 , please see Comparison of layout engines to get more information.

However you may get support of the XPATH 2.0 in Firefox by using Saxon-CE , see more on the MDN XSLT_2.0 page.

There is also Saxon CE , an open-source Javascript implementation of XSLT 2.0. Since XSLT 2.0 includes XPath 2.0, this provides an XPath 2.0 implementation in the browser. However it isn't built-in.

I just tried the current version of Safari (7.0.6) and it didn't accept the XPath 2.0 functions that I gave it:

> document.evaluate("starts-with('foo', 'f')", document.documentElement, null,
                 XPathResult.BOOLEAN_TYPE, null);
< XPathResult

> document.evaluate("ends-with('foo', 'o')", document.documentElement, null,
                 XPathResult.BOOLEAN_TYPE, null);
< Error: INVALID_EXPRESSION_ERR: DOM XPath Exception 51

So I'd say WebKit (specifically the JS engine, SquirrelFish / Nitro) doesn't currently support XPath 2.0.

Aug 2020 Update: The current successor to Saxon-CE is Saxon-JS 2, which supports XPath 3.1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM