Exist: bug in document-node(element(xxx))

Created on 9 Jun 2018  路  7Comments  路  Source: eXist-db/exist

What is the problem

Describe exactly what you see (e.g. an output of an XQuery)

declare namespace tei="http://www.tei-c.org/ns/1.0";
declare variable $play as document-node(element(tei:TEI)) := doc('/db/apps/shakespeare/data/ham.xml');
$play

returns zero results in eXist-db 4.0, although the play exists. It returns one result, as expected, in <oXygen/>.

What did you expect

I expected it to return the play:

document-node( E ) matches any document node that contains exactly one element node, optionally accompanied by one or more comment and processing instruction nodes, if E is an ElementTest or SchemaElementTest that matches the element node (see 2.5.5.3 Element Test and 2.5.5.4 Schema Element Test).

Example: document-node(element(book)) matches a document node containing exactly one element node that is matched by the ElementTest element(book).

(https://www.w3.org/TR/xpath-31/#id-matching-item)

Describe how to reproduce or add a test

Run the example above on an eXist-db installation with the Shakespeare app installed.

Context information

  • eXist-db version + Git Revision hash: eXist-db 4.0 / cc66ebc
  • Java version: java version "1.8.0_45", Java(TM) SE Runtime Environment (build 1.8.0_45-b14), Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
  • Operating system: MacOs 10.11.6 (15G20015)
  • 32 or 64 bit: 64 bit
  • How is eXist-db installed: JAR installer
  • Any custom changes: none
bug

Most helpful comment

Here is an xqsuite test demonstrating the failure:

xquery version "3.1";

module namespace mi = "http://exist-db.org/test/matching-item";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare
    %test:assertTrue
function mi:document() { 
    document { element book {} } instance of document-node()
};

declare
    %test:assertTrue
function mi:document-element() { 
    document { element book {} } instance of document-node( element() )
};

declare
    %test:assertTrue
function mi:document-element-name() { 
    document { element book {} } instance of document-node( element(book) )
};

This currently returns the following results:

<testsuites>
    <testsuite package="http://exist-db.org/test/matching-item"
        timestamp="2018-06-09T14:43:20.033-04:00" failures="1" pending="0"
        tests="3" time="PT0.009S">
        <testcase name="document" class="mi:document"/>
        <testcase name="document-element" class="mi:document-element"/>
        <testcase name="document-element-name" class="mi:document-element-name">
            <failure message="assertTrue failed." type="failure-error-code-1"/>
            <output>false</output>
        </testcase>
    </testsuite>
</testsuites>

All 7 comments

To fix this we need to fix #1463 first. Coming to think of it this seems a duplicate issue @joewiz ?
the bug is that the above is wrongly treated as:

document-node(document-node(tei:TEI))

Here is an xqsuite test demonstrating the failure:

xquery version "3.1";

module namespace mi = "http://exist-db.org/test/matching-item";

declare namespace test="http://exist-db.org/xquery/xqsuite";

declare
    %test:assertTrue
function mi:document() { 
    document { element book {} } instance of document-node()
};

declare
    %test:assertTrue
function mi:document-element() { 
    document { element book {} } instance of document-node( element() )
};

declare
    %test:assertTrue
function mi:document-element-name() { 
    document { element book {} } instance of document-node( element(book) )
};

This currently returns the following results:

<testsuites>
    <testsuite package="http://exist-db.org/test/matching-item"
        timestamp="2018-06-09T14:43:20.033-04:00" failures="1" pending="0"
        tests="3" time="PT0.009S">
        <testcase name="document" class="mi:document"/>
        <testcase name="document-element" class="mi:document-element"/>
        <testcase name="document-element-name" class="mi:document-element-name">
            <failure message="assertTrue failed." type="failure-error-code-1"/>
            <output>false</output>
        </testcase>
    </testsuite>
</testsuites>

I think as this is in the query processor it is probably one for @wolfgangmm

This bug is still present in eXist 5.0.0.

@duncdrum actually https://github.com/eXist-db/exist/issues/1463 is not related to this

@joewiz nice tests, but actually they are testing for something different to the issue that @djbpitt reported. I have incorporated both into a new PR.

@adamretter Approved by @dizzzz and now merged. Many thanks! And thanks to @djbpitt for reporting the issue! (See the tests that are now in the source code to prevent future regressions: https://github.com/eXist-db/exist/blob/develop/exist-core/src/test/xquery/document-nodes.xq.)

Was this page helpful?
0 / 5 - 0 ratings