diff --git a/exist-core/src/main/java/org/exist/xquery/FollowingSiblingSelector.java b/exist-core/src/main/java/org/exist/xquery/FollowingSiblingSelector.java index a8d906f788f..a6008d9fd08 100644 --- a/exist-core/src/main/java/org/exist/xquery/FollowingSiblingSelector.java +++ b/exist-core/src/main/java/org/exist/xquery/FollowingSiblingSelector.java @@ -103,13 +103,19 @@ public FollowingSiblingSelector(final NodeSet contextSet, final int contextId, @ for (final NodeProxy contextNode : precedingSiblings) { // System.out.println("\t\tSTART INNER LOOP: " + i); - if (Expression.NO_CONTEXT_ID == contextId) { -// System.out.println("\t\t\t" + followingSibling.getNodeId().toString() + " .copyContext(" + contextNode.getNodeId().toString() + ")"); - followingSibling.copyContext(contextNode); - } else { -// System.out.println("\t\t\t" + followingSibling.getNodeId().toString() + " .addContextNode(" + contextId + ", " + contextNode.getNodeId().toString() + ")"); - followingSibling.addContextNode(contextId, contextNode); - } + // START TEMP + if (followingSibling.getContext() == null || contextNode.getContext() == null + || followingSibling.getContext().getContextId() != contextNode.getContext().getContextId()) { + + if (Expression.NO_CONTEXT_ID == contextId) { + // System.out.println("\t\t\t" + followingSibling.getNodeId().toString() + " .copyContext(" + contextNode.getNodeId().toString() + ")"); + followingSibling.copyContext(contextNode); + } else { + // System.out.println("\t\t\t" + followingSibling.getNodeId().toString() + " .addContextNode(" + contextId + ", " + contextNode.getNodeId().toString() + ")"); + followingSibling.addContextNode(contextId, contextNode); + } + + } // END TEMP // System.out.println("\t\tEND INNER LOOP: " + i); // i++; diff --git a/exist-core/src/main/java/org/exist/xquery/PrecedingSiblingSelector.java b/exist-core/src/main/java/org/exist/xquery/PrecedingSiblingSelector.java index 96116f746c2..09dc7b0f1ff 100644 --- a/exist-core/src/main/java/org/exist/xquery/PrecedingSiblingSelector.java +++ b/exist-core/src/main/java/org/exist/xquery/PrecedingSiblingSelector.java @@ -138,13 +138,19 @@ public PrecedingSiblingSelector(final NodeSet contextSet, final int contextId, @ for (final NodeProxy precedingSibling : precedingSiblings) { // System.out.println("\t\tSTART INNER LOOP: " + i); - if (Expression.NO_CONTEXT_ID == contextId) { + // START TEMP + if (precedingSibling.getContext() == null || followingSibling.getContext() == null + || precedingSibling.getContext().getContextId() != followingSibling.getContext().getContextId()) { + + if (Expression.NO_CONTEXT_ID == contextId) { // System.out.println("\t\t\t" + precedingSibling.getNodeId().toString() + " .copyContext(" + followingSibling.getNodeId().toString() + ")"); - precedingSibling.copyContext(followingSibling); - } else { + precedingSibling.copyContext(followingSibling); + } else { // System.out.println("\t\t\t" + precedingSibling.getNodeId().toString() + " .addContextNode(" + contextId + ", " + followingSibling.getNodeId().toString() + ")"); - precedingSibling.addContextNode(contextId, followingSibling); - } + precedingSibling.addContextNode(contextId, followingSibling); + } + + } // END TEMP // System.out.println("\t\tEND INNER LOOP: " + i); // i++;