This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29660 - map:remove and array:remove should support removing multiple entries
Summary: map:remove and array:remove should support removing multiple entries
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.1 (show other bugs)
Version: Candidate Recommendation
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-05-24 16:06 UTC by Josh Spiegel
Modified: 2016-07-21 14:03 UTC (History)
0 users

See Also:


Attachments

Description Josh Spiegel 2016-05-24 16:06:07 UTC
I think it may improve usability if we modify map:remove to take a sequence of key values instead of a single key value.  This would make it easier to conditionally remove entries from a map.

Consider this map:

   declare variable $m := map {
     0 : "blue",
     2 : "red",
     4 : "blue",
     6 : "green"
   };

Assume the goal is to remove the "blue" entries without knowing the keys in advance.  I came up with two solutions for this.  The first uses a recursive user defined function:

  declare function local:removeAll($m as map(*), $keys) {
    if (exists($keys)) then
       local:removeAll(map:remove($m,$keys[1]), tail($keys))
    else
       $m
  };

  local:removeAll($m, map:keys($m)[$m(.) eq "blue"])

Here is another solution that filters and reconstructs:

  map:merge(
    for $k in map:keys($m)
    where $m($k) ne "blue"
    return 
      map:entry($k, $m($k))
  )


It is more succinct and I think more intuitive to use map:remove directly:

  map:remove($m, map:keys($m)[$m(.) eq "blue"])

If this change makes sense, then I expect we would want to consider making a similar change to array:remove as well.
Comment 1 Josh Spiegel 2016-05-27 15:53:45 UTC
This proposal was accepted at XML Query/XSL WG Joint Teleconference #644 on 2016-05-24.

DECISION: Modify map:remove() and array:remove() to allow multiple key arguments as requested by bug 29660.
Comment 2 Michael Kay 2016-05-28 17:43:37 UTC
The changes have been applied to the F+O 3.1 and XSLT 3.0 specifications (but not yet committed).