Questions tagged [xpath-3.1]

XPath 3.1 is the current version of XPath, finalized in March of 2017. It adds maps and arrays to XPath 3.0, as well as the arrow operator. Maps and arrays allow for JSON processing support. Use this tag for questions specific to XPath 3.1.

XPath 3.1 is the current version of XPath, it was finalized in March 2017, consisting of three specifications:

It builds on XPath 3.0, finalized in 2014.

The main new features in XPath 3.1 are the addition of maps and arrays to facilitate JSON processing and the arrow operator => which allows writing nested function calls like

tokenize((normalize-unicode(upper-case($string))),"\s+")

as

$string => upper-case() => normalize-unicode() => tokenize("\s+")

instead.

XPath 3.1 is supported on various platforms and with various host languages by implementations like

As XPath 3.1 is basically a subset of XQuery 3.1, any XQuery 3.1 implementation like BaseX also supports XPath 3.1.

Resources

36 questions
7
votes
1 answer

JSON serialization with XPath 3.1 fn:serialize

I am using XSLT 3.0 in Saxon-HE 9.8 and would like to work with JSON documents as linked data in JSON-LD. In JSON-LD, full HTTP URIs often appear as values. When I use the XPath 3.1 fn:serialize to round-trip the data back to JSON, the solidus…
tat
  • 321
  • 1
  • 19
4
votes
1 answer

XPath 3.1 expression to collect attributes as name/value maps for each selected node

XPath 3.1 supports a new map feature that allows maps in the result sequences. https://www.w3.org/TR/xpath-31/#id-maps For example, here is the valid XPath 3.1 expression that returns a hardcoded sequence of 2 maps: (map {'a':1,'b':2,'c':3}, map…
yurgis
  • 4,017
  • 1
  • 13
  • 22
3
votes
3 answers

Parsing a URL query string into a map of parameters with XPath

What would be the most readable way to parse a URL query string into a { 'param': 'value' } map in XSLT/XPath 3.0? Note: this is the inverse function of the one described in Building a URL query string from a map of parameters with XPath. Update: I…
3
votes
1 answer

Creating xsl:result-document with xpath 3.1 fn:transform using saxon 9.9 EE

I'd like to create an output document using the xpath 3.1 fn:transform. Following is A.xsl. It creates A.xml when run directly (from oxygen):
Caroline
  • 167
  • 1
  • 11
3
votes
2 answers

How can I implement a user-defined function with a name in the xpath expression?

I am using XSLT. I know the Inline Function Expressions, Is there some way to declare a named function in xpath expression? because I need the function name to implement a recursive call.
cmf41013
  • 107
  • 1
  • 9
3
votes
2 answers

How to use XPath 3.1 in Saxon?

I am currently using XPath 3.1 syntax but for some reason Saxon outputs the error: To use XPath 3.1 syntax, you must configure the XPath parser to handle it. How do I do this? Many thanks!!!
Yahya Uddin
  • 26,997
  • 35
  • 140
  • 231
2
votes
2 answers

What is the purpose/use of a map in XPath 3.1?

I understand the need for an array type in XPath 3.1 as they're fundamental to JSON. And yes I understand you can create a literal map() in an XPath query. But is there a way XML or JSON can be structured where a query would naturally return a map…
David Thielen
  • 28,723
  • 34
  • 119
  • 193
2
votes
2 answers

XPath 3.1 reference that's complete & succinct

I've been reading through the W3 spec for XPath 3.1, and it's way too long for most to read (they'll just quit). Is there an abbreviated specification anywhere? Our audience is users of our system that need to write an XPath statement to pull back…
David Thielen
  • 28,723
  • 34
  • 119
  • 193
2
votes
1 answer

Is tokenize($s) the same as tokenize($s, ' ')?

https://www.w3.org/TR/xpath-functions/#func-tokenize explains about the single argument version of tokenize: The one-argument form of this function splits the supplied string at whitespace boundaries. and then goes on to define or explain that…
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
1
vote
2 answers

How to write the Xpath for the json field having white space?

I want to write the xpath for a json field which is having white spaces in it. [ {"name":"Ram", "emai ld":"ram@gmail.com", "age":23}, {"name":"Shyam", "email id":"shyam23@gmail.com", "age":28} ] I tried as below to get the email…
1
vote
2 answers

XPath: How to sort a map?

I'm using a map for counting the number occurrences of, for example, each possible value of the attr attribute of the elem nodes:
Fravadona
  • 13,917
  • 1
  • 23
  • 35
1
vote
1 answer

Multiple string replacements

(updated question from 'static replace' to 'dynamic replace')
topskip
  • 16,207
  • 15
  • 67
  • 99
1
vote
1 answer

XPath to retrive XML tag value without Namespace and prefix

I have the following XML -
Sugata Bagchi
  • 123
  • 11
1
vote
1 answer

How does XPath deal with attributes which have conflicting expanded names?

Given the following document ... ... (Q1) What is the canonical result of this xpath 3.1 expression .. n2:doc/@n2:a ... if the…
Sean B. Durkin
  • 12,659
  • 1
  • 36
  • 65
1
vote
1 answer

Example of array and map for xslt 3.0 and xpath3.1

I want to use new feature in XPath3.1 like array and map, This might sound like a googleable question, but I try many example code still receive error message, here's how I got so far:
DaveG
  • 491
  • 1
  • 6
  • 19
1
2 3