On 28.12.2021 20:10, Eliot Kimber eliot(_dot_)kimber(_at_)servicenow(_dot_)com
wrote:
I couldn’t find an answer in my google and markmail searching so I
thought I’d 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()* {
dutils:_getDistinctNodes($nodes, ())
};
declare function dutils:_getDistinctNodes($nodes as node()*, $resultList
as node()*) as node()* {
if (exists($nodes))
then
let $node := head($nodes)
return dutils:_getDistinctNodes(tail($nodes), ($resultList | $node))
else $resultList
};
Which works but I feel like I’m missing some obvious way to do this more
directly, but I’m not seeing it.
Am I missing a better solution?
$nodes/.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--