25

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"]')
kjhughes
  • 106,133
  • 27
  • 181
  • 240
Ian Bytchek
  • 8,804
  • 6
  • 46
  • 72
  • possible duplicate of [What browsers support Xpath 2.0?](http://stackoverflow.com/questions/16658799/what-browsers-support-xpath-2-0) – Richard Aug 22 '14 at 20:54
  • I saw 16658799. Did you read the answer carefully? Do it first then. And then read mine again… – Ian Bytchek Aug 22 '14 at 20:58
  • None of the "big" browsers use XPath 2. There's your answer. Simple. – Arran Aug 22 '14 at 21:41

2 Answers2

25

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.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
12

Google Chrome (or Chromium) still uses libxml2 thus is limited to XPath 1.0. Cf. this Readme from the source.

Hille
  • 4,096
  • 2
  • 22
  • 32
  • Here's a still-live link from StackOverflow about [libxml2 not implementing XPath 2.0](https://stackoverflow.com/a/26164535/290085). – kjhughes Nov 22 '18 at 15:15