Working with eXist 5.2, the position function returns what appears to be a 0-based index instead of 1-based as required:
let $a := <a>
<b n="a"/>
<b n="b"/>
<b n="c"/>
</a>
return $a/b[@n=('b', 'c')]/position()
returns
0
1
instead of the expected
1
2
To Reproduce
The follow xQuery test tests for the proper results.
xquery version "3.1";
module namespace t="http://exist-db.org/xquery/test";
declare namespace test="http://exist-db.org/xquery/xqsuite";
declare variable $t:XML := document {
<a>
<b n="a"/>
<b n="b"/>
<b n="c"/>
</a>
};
declare
%test:assertTrue
function t:test() {
let $r := $t:XML/a/b[@n=('b', 'c')]/position()
return count($r) eq 2 and $r[1] eq 1 and $r[2] eq 2
};
Context (please always complete the following information):
Additional context
conf.xml? NoI can reproduce the issue on 5.1.1
Any predicate will cause the position() to be off by one. Both in-memory and persisted nodes are affected.
xquery version "3.1";
declare variable $local:XML := document {
<a>
<b n="a"/>
<b n="b"/>
<b n="c"/>
</a>
};
xmldb:store('/db/temp', 'stored.xml', $local:XML),
$local:XML/a/position(),
doc('/db/temp/stored.xml')/a/position(),
$local:XML/a[true()]/position(),
doc('/db/temp/stored.xml')/a[true()]/position()
Most helpful comment
I can reproduce the issue on 5.1.1
Any predicate will cause the
position()to be off by one. Both in-memory and persisted nodes are affected.