<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29743</bug_id>
          
          <creation_ts>2016-07-20 05:07:06 +0000</creation_ts>
          <short_desc>XPath 3.1 maps recursive descent</short_desc>
          <delta_ts>2016-09-23 08:43:09 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>XPath 3.1</component>
          <version>Working drafts</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jorge L Williams">jorge.williams</reporter>
          <assigned_to name="Jonathan Robie">jonathan.robie</assigned_to>
          <cc>andrew_coleman</cc>
    
    <cc>mike</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>126991</commentid>
    <comment_count>0</comment_count>
    <who name="Jorge L Williams">jorge.williams</who>
    <bug_when>2016-07-20 05:07:06 +0000</bug_when>
    <thetext>We use JSONPath (http://goessner.net/articles/JsonPath/) along side of XPath, when working with JSON data.  Now that XPath supports maps and JSON, I&apos;ve started evaluating  whether it may be worth consolidating around XPath exclusively.  This would certainly make our lives easier especially as JSONPath implementations vary wildly.

One feature that appears to be missing, but which is used quite often by our lazy developers is recursive decent ( .. in JSONPath).

Notice the examples here: http://goessner.net/articles/JsonPath/  it&apos;s a bit of a challenge to replicate them with XPath 3.1.

I&apos;ve created a function in XQuery which I believe captures what JSONPath is doing and it looks like this:

declare function r:d($m as item()) as item()* {
  let $funs := $m?*[. instance of map(*) or . instance of array(*)]
  let $mps := $funs[. instance of map(*)]
  return  ($mps, $funs ! r:d(.))
};

Given that I can replicate all of the examples :

| Description                        | JSONPath                | XPath 3.1                           |
|------------------------------------+-------------------------+-------------------------------------|
| All of the authors of a book       | $.store.book[*].author  | $_?store?book?*?author              |
| All authors                        | $..author               | r:d($_)?author                      |
| All things in the store            | $.store.*               | $_?store?*                          |
| The price of everything in a store | $.store..price          | r:d($_?store)?price                 |
| The third book                     | $..book[ 2 ]            | r:d($_)?book?3                      |
| The last book in order             | $..book[(@.length-1)]   | r:d($_)?book?*[position() = last()] |
|                                    | $..book[-1:]            |                                     |
| The first two books                | $..book[0,1]            | r:d($_)?book?(1, 2)                 |
|                                    | $..book[:2]             | r:d($_)?book?(1 to 2)               |
| Filter all books with isbn number  | $..book[?(@.isbn)]      | r:d($_)?book?*[?isbn]               |
| Filtar all books cheaper than 10   | $..book[?(@.price&lt; 10)] | r:d($_)?book?*[?price &lt; 10]         |
| All members of JSON structure      | $..*                    | r:d($_)                             |

Defining a function to do this doesn&apos;t seem right though. I must be missing something...or there is a gap.

Thanks.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127310</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-09-06 19:28:13 +0000</bug_when>
    <thetext>Thank you for this usability feedback on the specification.

After some consideration, the working group decided that a good part of the requirement could be met with a new function 

map:find($input as item()*, $key as xs:anyAtomic) as array(*)

which searches $input recursively looking into contained maps at any depth to find an entry with key $key, and returning the associated values as members of the result array.

This clearly doesn&apos;t satisfy all these examples but we felt it had the right blend of simplicity and capability, given how close we are to finishing. New syntax at this stage was felt to be far too risky. 

The WG has approved an outline sketch of the specification and will move on to consider the final proposed specification.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127511</commentid>
    <comment_count>2</comment_count>
    <who name="Andrew Coleman">andrew_coleman</who>
    <bug_when>2016-09-23 08:43:09 +0000</bug_when>
    <thetext>The function map:find() is available to review in the editor&apos;s draft of the F&amp;O spec:
https://www.w3.org/XML/Group/qtspecs/specifications/xpath-functions-31/html/#func-map-find

Marking this bug resolved/fixed.
Many thanks for raising this issue.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>