[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 Wed, Dec 29, 2021 at 10:27 AM Martin Honnen martin.honnen@xxxxxx < xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote: > I don't have to know one, I just pointed out that the spec doesn't > guarantee the order. Thus I don't see why, given the spec, one should > expect any implementation to preserve the order. I am happy to state that the provided solution produces the correct result on all currently-existing XPath engines :) If one is about to be starved to death and there is a banana hanging inches from his mouth, but the documentation says that there is no guarantee that there is food nearby, what would be the best thing to do: - don't pick the banana and die, as per specification - acknowledge the reality and **live** in this reality Cheers, Dimitre P.S. If we were more pedantic, we could sort the results of distinct-values() before using them. On 29.12.2021 17:36, Dimitre Novatchev dnovatchev@xxxxxxxxx wrote: > > > > > > On Wed, Dec 29, 2021 at 12:21 AM Martin Honnen martin.honnen@xxxxxx > > <mailto:martin.honnen@xxxxxx> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx > > <mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>> wrote: > > > > > > Am 29.12.2021 um 00:32 schrieb Dimitre Novatchev > > dnovatchev@xxxxxxxxx <mailto:dnovatchev@xxxxxxxxx>: > >> > >> > >> > >> > >> Hit Send too early: > >> > >> Do notice: this seems the only solution of all presented so far, > >> that preserves the original sequence order (not document order) of > >> the nodes. > > > > Why is the original sequence order preserved? > > https://www.w3.org/TR/xpath-functions/#func-distinct-values > > <https://www.w3.org/TR/xpath-functions/#func-distinct-values> > > clearly says > > > > "The function returns the sequence that results from removing > > from|$arg|all but one of a set of values that are considered equal > > to one another. [...] > > > > The order in which the sequence of values is returned > > isB7implementation-dependentB7 > > <https://www.w3.org/TR/xpath-functions/#implementation-dependent>. > > > > Which value of a set of values that compare equal is returned > > isB7implementation-dependentB7 > > <https://www.w3.org/TR/xpath-functions/#implementation-dependent>." > > > > > > So while > > > > $nodes ! generate-id(.) > > > > gives you the generated ids in the order of the nodes in $nodes > > after the call to distinct-values there is no order defined, it is > > implementation dependent. > > > > > > @Martin Honnen <mailto:Martin.Honnen@xxxxxx> Could you, please, give us > > an example of an existing XPath engine whose implementation of > > `distinct-values()` produces its results in any other order than their > > original order in the input sequence? > > I don't have to know one, I just pointed out that the spec doesn't > guarantee the order. Thus I don't see why, given the spec, one should > expect any implementation to preserve the order. > > Imagine you implement distinct-values in .NET with e.g. > > https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.distinct?v iew=net-6.0 > and it would probably pass all tests but also only give a "result > sequence" that " is unordered". > > Aren't there also implementations of XQuery or XPath that exploit > parallel processing? I could imagine such an implementation to easily > not care about ordering if the spec allows it for distinct-values. > > It seems, on the other hand, eXide of eXist-db in the online version > doesn't even grok some of the generate-id based attempts: > > let $nodes := (1 to 10) ! parse-xml-fragment('<node>' || . || > '</node>')/node(), > $nodes := (1 to 5) ! $nodes, > $ids := distinct-values($nodes ! generate-id(.)) > return $ids ! (function($id) {$nodes[generate-id(.) eq $id][1]})(.) > > gives <node>1</node> > > > > Any eXist-db users reading here? Is there a known issue with generate-id? > > > -- Cheers, Dimitre Novatchev --------------------------------------- Truly great madness cannot be achieved without significant intelligence. --------------------------------------- To invent, you need a good imagination and a pile of junk ------------------------------------- Never fight an inanimate object ------------------------------------- To avoid situations in which you might make mistakes may be the biggest mistake of all ------------------------------------ Quality means doing it right when no one is looking. ------------------------------------- You've achieved success in your field when you don't know whether what you're doing is work or play ------------------------------------- To achieve the impossible dream, try going to sleep. ------------------------------------- Facts do not cease to exist because they are ignored. ------------------------------------- Typing monkeys will write all Shakespeare's works in 200yrs.Will they write all patents, too? :) ------------------------------------- Sanity is madness put to good use. ------------------------------------- I finally figured out the only reason to be alive is to enjoy it.
|
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
|