Skip to content

Commit 6ccae3b

Browse files
author
Nico Verwer
committed
When converting eXist nodes into Xdm nodes, use the document node for indexing.
1 parent 0ec448d commit 6ccae3b

File tree

1 file changed

+8
-1
lines changed
  • exist-core/src/main/java/org/exist/xquery/functions/fn/transform

1 file changed

+8
-1
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/transform/TreeUtils.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@ static StringBuilder pathTo(final Node node) {
6464
static List<Integer> treeIndex(final Node node) {
6565
final Node parent = node.getParentNode();
6666
if (parent == null) {
67-
return new ArrayList<>();
67+
final List<Integer> index = new ArrayList<>();
68+
// The root element always index 0 within the document node.
69+
// Some node implementations (e.g., org.exist.dom.memtree.NodeImpl) do not always have an associated document.
70+
// In this case, the nodeIndex must get an extra 0 index to be valid for xdmDocument.
71+
if (! (node instanceof Document)) {
72+
index.add(0);
73+
}
74+
return index;
6875
}
6976
final List<Integer> index = treeIndex(parent);
7077
Node sibling = node.getPreviousSibling();

0 commit comments

Comments
 (0)