[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[Recent Entries]
[Reply To This Message]
Re: XQuery/XPath 3.1: Node List to Node Set ("distinct
On 28.12.2021 20:10, Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx wrote:
I couldnbt find an answer in my google and markmail searching so I
thought Ibd ask here:
Given an arbitrary list of nodes that may contain duplicates, what is
the most efficient way to reduce the node list to a set?
The solution I came up with is a recursive function:
(:
Get the unique nodes from the supplied sequence
@param nodes The sequence of nodes to evaluate
@return A sequence of nodes such that each node in $nodes exists exactly
once.
:)
declare function dutils:distinctNodes($nodes as node()*) as node()* {
B dutils:_getDistinctNodes($nodes, ())
};
declare function dutils:_getDistinctNodes($nodes as node()*, $resultList
as node()*) as node()* {
B if (exists($nodes))
B then
B let $node := head($nodes)
B return dutils:_getDistinctNodes(tail($nodes), ($resultList | $node))
B else $resultList
};
Which works but I feel like Ibm missing some obvious way to do this more
directly, but Ibm not seeing it.
Am I missing a better solution?
$nodes/.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format
RSS 2.0 |
|
Atom 0.3 |
|
|