Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element constructor creates document node. It should not. #1463

Closed
mjhallman opened this issue Jun 23, 2017 · 7 comments · Fixed by #4402 · May be fixed by #4031
Closed

Element constructor creates document node. It should not. #1463

mjhallman opened this issue Jun 23, 2017 · 7 comments · Fixed by #4402 · May be fixed by #4031
Assignees
Labels
bug issue confirmed as bug high prio xquery issue is related to xquery implementation
Milestone

Comments

@mjhallman
Copy link

mjhallman commented Jun 23, 2017

let $x := element {"root"}  {}

return $x/root() instance of document-node()

This returns true in eXist-db which is incorrect. The result of $x/root() should be an element().
I have tested this on Saxon and BaseX which both correctly return false.

@dizzzz
Copy link
Member

dizzzz commented Jun 23, 2017

please could you fill in the issue-template? It makes sure you'll add all required information, info we need to understand the exact context. thnx

@adamretter
Copy link
Contributor

@dizzzz I helped @mjhallman report these. Everything that is needed to reproduce is there.

@adamretter adamretter added the bug issue confirmed as bug label Jun 23, 2017
@adamretter
Copy link
Contributor

It's the HEAD of the develop branch.

@adamretter
Copy link
Contributor

A little investigation has shown that the problem is actually fn:root. In-memory elements in eXist-db always have an Owner Document, which they should not when directly constructed with element x {}, and so fn:root always returns the document-node() by mistake.

See the examples here: https://www.w3.org/TR/xpath-functions/#func-root-examples

The following XQUnits show the issue:

declare
    %test:assertEquals("false")
function root:in-mem-element() {
    fn:root(<anything/>) instance of document-node()
};

The above should return false, but eXist-db returns true.

declare
    %test:assertEquals("true")
function root:in-mem-document() {
    fn:root(document { <anything/> }) instance of document-node()
};

The above should (and does in eXist-db) return true.

@adamretter
Copy link
Contributor

adamretter commented Nov 21, 2017

@wolfgangmm I would welcome a discussion about this. From my perspective it requires quite some re-engineering of the in-memory DOM model, but before I do that... maybe you have some clever ideas to fix this up?

@wolfgangmm
Copy link
Member

@adamretter we know where the in-memory DOM is created by a constructor, so could just set a flag.

@adamretter adamretter modified the milestones: eXist-3.6.0, eXist-3.7.0 Nov 27, 2017
@adamretter adamretter modified the milestones: eXist-3.7.0, eXist-4.0.1 Feb 14, 2018
@adamretter adamretter modified the milestones: eXist-4.0.1, 4.1.1 Apr 18, 2018
@duncdrum
Copy link
Contributor

duncdrum commented May 8, 2018

Yes someone working on tei-publisher just stumbled on fn:root()

xquery version "3.0";
declare function local:node-kind
  ( $nodes as node()* )  as xs:string* {

 for $node in $nodes
 return
 if ($node instance of element()) then 'element'
 else if ($node instance of attribute()) then 'attribute'
 else if ($node instance of text()) then 'text'
 else if ($node instance of document-node()) then 'document-node'
 else if ($node instance of comment()) then 'comment'
 else if ($node instance of processing-instruction())
         then 'processing-instruction'
 else 'unknown'
 } ;

let $data :=
<root xml:base="bl">
    <dummy/>
</root>

return
    local:node-kind(root($data))

exist 4.1.0 returns: document-node
Saxon 9.8.0.8 returns: element
Zorba 2.9: returns: element

I also think this is wrong, fn:doc() should give you access to document-nodes, root should not return document-node here.

@adamretter adamretter modified the milestones: eXist-4.3.2, eXist-4.4.1 Sep 21, 2018
@duncdrum duncdrum modified the milestones: eXist-4.4.1, eXist-4.5.1 Nov 30, 2018
@joewiz joewiz modified the milestones: eXist-4.5.1, eXist-4.6.2 Apr 6, 2019
@joewiz joewiz modified the milestones: eXist-4.6.2, eXist 4.7.1 May 24, 2019
@adamretter adamretter modified the milestones: eXist-4.7.1, eXist-4.7.2 Aug 14, 2019
@line-o line-o added the xquery issue is related to xquery implementation label Apr 8, 2020
@line-o line-o modified the milestones: eXist-4.7.2, eXist-5.3.0 Apr 8, 2020
dizzzz added a commit to dizzzz/exist that referenced this issue Apr 10, 2021
@line-o line-o modified the milestones: eXist-5.3.0, eXist-6.0.0 Jun 28, 2021
@adamretter adamretter modified the milestones: eXist-6.0.0, eXist-7.0.0 Feb 14, 2022
adamretter added a commit to evolvedbinary/exist that referenced this issue Jun 15, 2022
adamretter added a commit to evolvedbinary/exist that referenced this issue Jun 15, 2022
adamretter added a commit to evolvedbinary/exist that referenced this issue Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issue confirmed as bug high prio xquery issue is related to xquery implementation
Projects
None yet
7 participants