[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

Subject: Re: XQuery/XPath 3.1: Node List to Node Set ("distinct nodes")
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 30 Dec 2021 17:44:15 -0000
Re:  XQuery/XPath 3.1: Node List to Node Set ("distinct
> - If order of the sequence must be maintained, consider fold-left() or
fold-right() I suppose
>   - but test it!

I would definitely prefer the index-of() - based solution: for being:
  -  shortest
  - with least moving parts and surface
  - shown in actual performance measurements to be not slower (actually,
was slightly faster) than the fold - based solutions provided in this thread
  - shown to work with both BaseX and Saxon (while one of the fold-based
solutions was being evaluated incorrectly in Saxon due to a bug)

Thanks Eliot and everyone! Happy New Year!
Dimitre

On Thu, Dec 30, 2021 at 6:46 AM Wendell Piez wapiez@xxxxxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Hmm....
>
> Takeaways for me seem to be:
>
> - For the operation in question, prefer "$nodes/." or perhaps
> "$nodes/self::node()" or $nodes/self::* as appropriate, plus a comment
> - If order of the sequence must be maintained, consider fold-left() or
> fold-right() I suppose
>   - but test it!
> - except and intersect (to say nothing of union) also have some
> interesting uses and applications
>
> Meanwhile it is very reassuring and an education to see these things
> worked out. This problem actually has real-world applications for me too -
> and the $nodes in question could be documents....
>
> Thanks Eliot! Happy New Year!
> Wendell
>
>
> On Wed, Dec 29, 2021 at 6:25 PM Dimitre Novatchev dnovatchev@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> > No, it doesn't seem to be fixed, Mike's implementation seems to try be
>> > smarter than the spec allows and his own coding assumes :)
>>
>> Seems BaseX rules!
>>
>> And glad to be a contributor to the eventual future improvement of Saxon
>> :)
>>
>> Cheers,
>> Dimitre
>>
>> On Wed, Dec 29, 2021 at 12:17 PM Martin Honnen martin.honnen@xxxxxx <
>> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>>
>>> On 29.12.2021 20:59, Dimitre Novatchev dnovatchev@xxxxxxxxx wrote:
>>> >   document (fragments?) are involved.
>>> >
>>> > Yes, bugs happen...
>>> >
>>> > Just trying to evaluate Dr. Kay's fold-left solution with Saxon
>>> (EE9.1.7
>>> > via Oxygen) I am getting a result of 20 nodes but the correct must be
>>> > just 3 nodes. BaseX correctly evaluates the XPath expression and
>>> > produces the right 3-nodes result.
>>> >
>>> > Xml document:
>>> > <t>
>>> >    <a/>
>>> >    <b/>
>>> >    <c/>
>>> > </t>
>>> >
>>> > XSLT stylesheet:
>>> >
>>> > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform
>>> > <http://www.w3.org/1999/XSL/Transform>" version="3.0">
>>> >    <xsl:output omit-xml-declaration="yes"/>
>>> >    <xsl:template match="/">
>>> >      <xsl:sequence select=
>>> >        "let $xml := /,
>>> >        $nodes := (/*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a,
>>> > /*/b,
>>> >        /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
>>> >        /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
>>> >        /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
>>> >        /*/a, /*/c, /*/b, /*/a, /*/b )
>>> >        return
>>> >          $nodes => fold-left((), function($all, $this) {$all, $this
>>> > except $all})"/>
>>> >    </xsl:template>
>>> > </xsl:stylesheet>
>>> >
>>> > Result produced when run with Saxon-EE (and also PE) 9.9.1.7 via
>>> Oxygen:
>>> >
>>> >
>>> <a/><c/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/><b/>
>>> >
>>> > Evaluating the below expression with Saxon-EE XQuery9.9.1.7 also
>>> > produces the same unexpected result:
>>> >
>>> > let $xml := parse-xml("<t><a/><b/><c/></t>"),
>>> >      $nodes := ($xml/*/a, $xml/*/c, $xml/*/b, $xml/*/a, $xml/*/b,
>>> > $xml/*/a, $xml/*/c, $xml/*/b, $xml/*/a, $xml/*/b, $xml/*/a, $xml/*/c,
>>> > $xml/*/b, $xml/*/a, $xml/*/b, $xml/*/a, $xml/*/c, $xml/*/b, $xml/*/a,
>>> > $xml/*/b, $xml/*/a, $xml/*/c, $xml/*/b, $xml/*/a, $xml/*/b, $xml/*/a,
>>> > $xml/*/c, $xml/*/b, $xml/*/a, $xml/*/b,$xml/*/a, $xml/*/c, $xml/*/b,
>>> > $xml/*/a, $xml/*/b, $xml/*/a, $xml/*/c, $xml/*/b, $xml/*/a, $xml/*/b,
>>> > $xml/*/a, $xml/*/c, $xml/*/b, $xml/*/a, $xml/*/b )
>>> >    return
>>> >      $nodes => fold-left((), function($all, $this) {$all, $this except
>>> > $all})
>>> >
>>> > Hopefully this is fixed in the next versions of Saxon?
>>>
>>> No, it doesn't seem to be fixed, Mike's implementation seems to try be
>>> smarter than the spec allows and his own coding assumes :)
>>>
>>> Saxon-JS 2.3 gets
>>>
>>> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>> version="3.0">
>>>    <xsl:output omit-xml-declaration="yes"/>
>>>    <xsl:template match="/">
>>>      <xsl:sequence select=
>>>        "let $xml := /,
>>>        $nodes := (/*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a,
>>> /*/b,
>>>        /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
>>>        /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
>>>        /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
>>>        /*/a, /*/c, /*/b, /*/a, /*/b )
>>>        return
>>>          fold-left($nodes, (), function($all, $this) {$all, $this except
>>> $all})"/>
>>>    </xsl:template>
>>> </xsl:stylesheet>
>>>
>>> right but SaxonCS and Saxon HE 10.6 don't.
>>>
>>>
>>>
>>
>> --
>> 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.
>>
>> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
>> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/174322> (by
>> email)
>>
>
>
> --
> ...Wendell Piez... ...wendell -at- nist -dot- gov...
> ...wendellpiez.com... ...pellucidliterature.org... ...pausepress.org...
> ...github.com/wendellpiez... ...gitlab.coko.foundation/wendell...
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
> email <>)
>


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

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.