[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XQuery/XPath 3.1: Node List to Node Set ("distinct no

Subject: XQuery/XPath 3.1: Node List to Node Set ("distinct nodes")
From: "Eliot Kimber eliot.kimber@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 28 Dec 2021 19:09:50 -0000
 XQuery/XPath 3.1: Node List to Node Set ("distinct  no
I couldnt find an answer in my google and markmail searching so I thought Id
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 Im missing some obvious way to do this more
directly, but Im not seeing it.

Am I missing a better solution?

Thanks,

Eliot

_____________________________________________
Eliot Kimber
Sr Staff Content Engineer
O: 512 554 9368
M: 512 554 9368
servicenow.com<https://www.servicenow.com>
LinkedIn<https://www.linkedin.com/company/servicenow> |
Twitter<https://twitter.com/servicenow> |
YouTube<https://www.youtube.com/user/servicenowinc> |
Facebook<https://www.facebook.com/servicenow>

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.