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

Subject: Re: [xsl] XQuery/XPath 3.1: Node List to Node Set ("distinct nodes")
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 29 Dec 2021 20:17:09 -0000
On 29.12.2021 20:59, Dimitre Novatchev dnovatchev@xxxxxxxxx wrote:
B B 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>
 B  <a/>
 B  <b/>
 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">
 B  <xsl:output omit-xml-declaration="yes"/>
 B  <xsl:template match="/">
 B  B  <xsl:sequence select=
 B  B  B  "let $xml := /,
 B  B  B  $nodes := (/*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a,
/*/b,
 B  B  B  /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
 B  B  B  /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
 B  B  B  /*/a, /*/c, /*/b, /*/a, /*/b, /*/a, /*/c, /*/b, /*/a, /*/b,
 B  B  B  /*/a, /*/c, /*/b, /*/a, /*/b )
 B  B  B  return
 B  B  B  B  $nodes => fold-left((), function($all, $this) {$all, $this
except $all})"/>
 B  </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>"),
 B  B  $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 )
 B  return
 B  B  $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.

Current Thread