diff --git a/exist-core/src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java b/exist-core/src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java index ed5f630028d..a765adc29d8 100644 --- a/exist-core/src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java +++ b/exist-core/src/main/java/org/exist/dom/persistent/NewArrayNodeSet.java @@ -792,6 +792,7 @@ public NodeSet selectFollowing(final NodeSet pl, final int position, final int c if(!reference.getNodeId().isDescendantOf(nodes[j].getNodeId())) { if(position < 0 || ++n == position) { if (contextId != Expression.IGNORE_CONTEXT + && contextId != Expression.NO_CONTEXT_ID && nodes[j].getContext() != null && reference.getContext() != null && nodes[j].getContext().getContextId() == reference.getContext().getContextId()) { @@ -846,6 +847,7 @@ public NodeSet selectPreceding(final NodeSet pl, final int position, if(!reference.getNodeId().isDescendantOf(nodes[j].getNodeId())) { if(position < 0 || ++n == position) { if (contextId != Expression.IGNORE_CONTEXT + && contextId != Expression.NO_CONTEXT_ID && nodes[j].getContext() != null && reference.getContext() != null && nodes[j].getContext().getContextId() == reference.getContext().getContextId()) { diff --git a/exist-core/src/test/xquery/axes-persistent-nodes.xqm b/exist-core/src/test/xquery/axes-persistent-nodes.xqm index d9984336a2c..ece5539b2be 100644 --- a/exist-core/src/test/xquery/axes-persistent-nodes.xqm +++ b/exist-core/src/test/xquery/axes-persistent-nodes.xqm @@ -102,6 +102,25 @@ function axpn:preceding-with-predicate-db-map() { ! (./@id || ":" || (./preceding::pb[1]/@id, "PRECEDING_PB_NOT_FOUND")[1]) }; +declare + %test:assertEquals("w1:pb1", "w2:pb1", "w3:pb1", "w4:pb2", "w5:pb2") +function axpn:preceding-with-context-predicate-db-flwor() { + for $w in doc("/db/test/test.xml")//w[exists(.)] + let $preceding-page := $w/preceding::pb[1] + return + if ($preceding-page) then + $w/@id || ":" || $preceding-page/@id + else + $w/@id || ":PRECEDING_PB_NOT_FOUND" +}; + +declare + %test:assertEquals("w1:pb1", "w2:pb1", "w3:pb1", "w4:pb2", "w5:pb2") +function axpn:preceding-with-context-predicate-db-map() { + doc("/db/test/test.xml")//w[exists(.)] + ! (./@id || ":" || (./preceding::pb[1]/@id, "PRECEDING_PB_NOT_FOUND")[1]) +}; + declare %test:assertEquals("w1:pb1", "w2:pb1", "w3:pb1", "w4:pb2", "w5:pb2") function axpn:preceding-without-predicate-flwor() { @@ -161,6 +180,25 @@ function axpn:following-with-predicate-db-map() { ! (./@id || ":" || (./following::pb[1]/@id, "FOLLOWING_PB_NOT_FOUND")[1]) }; +declare + %test:assertEquals("w1:pb2", "w2:pb2", "w3:pb2", "w4:pb3", "w5:pb3") +function axpn:following-with-context-predicate-db-flwor() { + for $w in doc("/db/test/test.xml")//w[exists(.)] + let $following-page := $w/following::pb[1] + return + if ($following-page) then + $w/@id || ":" || $following-page/@id + else + $w/@id || ":FOLLOWING_PB_NOT_FOUND" +}; + +declare + %test:assertEquals("w1:pb2", "w2:pb2", "w3:pb2", "w4:pb3", "w5:pb3") +function axpn:following-with-context-predicate-db-map() { + doc("/db/test/test.xml")//w[exists(.)] + ! (./@id || ":" || (./following::pb[1]/@id, "FOLLOWING_PB_NOT_FOUND")[1]) +}; + declare %test:assertEquals("w1:pb2", "w2:pb2", "w3:pb2", "w4:pb3", "w5:pb3") function axpn:following-without-predicate-flwor() {