saxon:map-search
Searches recursively through a structure of nested maps and arrays.
map-search($input as item()*, $key as xs:anyAtomicType) ➔ map(*)*
Arguments | ||||
| $input | item()* | The input sequence to be searched | |
| $key | xs:anyAtomicType | The key value to be found | |
Result | map(*)* | |||
map-search($input as item()*, $key as xs:anyAtomicType, $condition as function(item()) as xs:boolean) ➔ map(*)*
Arguments | ||||
| $input | item()* | The input sequence to be searched | |
| $key | xs:anyAtomicType | The key value to be found | |
| $condition | function(item()) as xs:boolean | Predicate that the found entry must satisfy | |
Result | map(*)* | |||
Namespace
http://saxon.sf.net/
Saxon availability
Requires Saxon-PE or Saxon-EE. Available for all platforms.
Notes on the Saxon implementation
Available since Saxon 9.9. Reimplemented in Saxon 13 to use JNodes.
Details
The function saxon:map-search is similar to map:find, in that it searches recursively through
nested maps and arrays, but is more versatile. It differs from map:find in
two main respects:
- Whereas
map:findonly takes as input the key value to look for,saxon:map-searchalso takes a function that can be used to test the associated value. - Whereas
map:findreturns the value associated with the specified key,saxon:map-searchreturns a JNode, which contains much more information about where the match was found.
In more detail:
The function saxon:map-search searches the
sequence supplied as $input looking for map entries whose key is the same
key as $key. When such an entry is found, the associated value is passed to
the supplied $condition function. If the $condition function
returns true, or if there is no $condition, then an item is added to the
returned value of the function: so the returned value is a sequence containing one item
for each search "hit". The actual item representing a hit is a JNode, allowing use of
axes such as the parent and ancestor axes to navigate from the returned JNode to related
nodes in the tree that was searched.
The search processes the $input sequence using the following
recursively-defined rules:
- To process a sequence, process each of its items in order.
- Each array or map in the
$inputsequence is marked as a pedigree root. - To process an item that is an array, then process each of the array's members in order (each member is, in general, a sequence).
- To process an item that is a map, then for each key-value entry (K, V) in the map
(in implementation-dependent order) perform both of the following steps, in order:
- If K is the same key as
$key, then add a new map to the result sequence (with entries "key", "value", and "map" as described above). - Process V (which is, in general, a sequence).
- If K is the same key as
- To process an item that is neither a map nor an array, do nothing. (Such items are ignored).