saxon:with-pedigree

Takes a map or array as input, and returns a new map or array with the same content, whose implementation tracks downward selections within a JSON-like structure of maps or arrays, so that it is possible to trace from a selected item to the route by which it was selected.

with-pedigree($in as function(*)) ➔ function(*)

Arguments

 

$in

function(*)

The input map or array

Result

function(*)

Namespace

http://saxon.sf.net/

Saxon availability

Requires Saxon-PE or Saxon-EE. Implemented since Saxon 9.9.

Notes on the Saxon implementation

Available since Saxon 9.9.

Details

If the supplied value is a map or array, the with-pedigree() function returns a new map or array with the same content, but having an internal implementation that tracks downward selections within a tree of maps and arrays, such as might be obtained by parsing JSON input.

If the supplied argument is a function that is not a map or array, it is returned unchanged.

The functions and operators that constitute "downwards selection" include:

  1. map:get($M, $K) and its equivalents $M($K) or $M?($K)
  2. array:get($A, $I) and its equivalents $A($I) or $A?($I)
  3. $V?* where $V is either a map or an array
  4. array:subarray(), array:remove(), array:head(), array:tail()
  5. map:find()

Any maps or arrays returned by these functions and operators (but not other values, such as nodes and atomic values) will have a pedigree that can be obtained using the saxon:pedigree() function. The pedigree is represented as a map containing a number of entries: the "container" entry holds the immediately containing map or array; the "key" entry (where applicable) holds the key of the value within the containing map; the "index" entry (where applicable) holds the 1-based index of the value within the containing array. The container will itself have a pedigree, so it is possible to navigate upwards through the tree back to the root.

See also:

saxon:pedigree()