xsl-list
[Top] [All Lists]

Re: [xsl] XQuery/XPath 3.1: Node List to Node Set ("distinct nodes")

2021-12-29 11:57:33
Dimitre,

Thanks—I see now that I had the parameters reversed—I didn’t read the spec 
carefully enough and assumed that the order of the parameters to fold-left 
matched the order of the parameters to the function.

Cheers,

E.



_____________________________________________
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>

From: Dimitre Novatchev dnovatchev(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Date: Wednesday, December 29, 2021 at 10:51 AM
To: xsl-list <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: Re: [xsl] XQuery/XPath 3.1: Node List to Node Set ("distinct nodes")
[External Email]

On Wed, Dec 29, 2021 at 7:25 AM Eliot Kimber 
eliot(_dot_)kimber(_at_)servicenow(_dot_)com<mailto:eliot(_dot_)kimber(_at_)servicenow(_dot_)com>
 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>>
 wrote:
So given this expression:

fold-left($nodes, (), function($a, $n) { $a, $n except $a })

I understand this to be iterating over $nodes from left to right, applying 
the function function($a, $n) to each node, where $a is the next node and $n 
is the accumulated value (being the result returned by the
  function on each invocation).

The “$a, $n except $a” in the function body constructs a new sequence of ($a, 
$n), excluding $a if it is already in $n. This sequence is then passed as the 
second parameter of the next invocation of the
function. This has the effect of preserving the order of input node list.

Actually, $a is the accumulated result, and $n is the head of the remaining 
sequence -- as per spec.

And if it were as quated above, we would get the in the results the last 
occurrence of each item, not the first.

Cheers,
Dimitre
--~----------------------------------------------------------------
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
--~--
<Prev in Thread] Current Thread [Next in Thread>