File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed
exist-core/src/main/java/org/exist/xquery/functions/fn/transform Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change 24
24
25
25
import net .sf .saxon .s9api .XdmNode ;
26
26
import org .exist .xquery .value .NodeValue ;
27
+ import org .w3c .dom .Attr ;
27
28
import org .w3c .dom .Document ;
28
29
import org .w3c .dom .Node ;
29
30
@@ -74,17 +75,31 @@ static List<Integer> treeIndex(final Node node) {
74
75
return index ;
75
76
}
76
77
final List <Integer > index = treeIndex (parent );
77
- Node sibling = node . getPreviousSibling ( );
78
+ Node sibling = previousSiblingNotAttribute ( node );
78
79
int position = 0 ;
79
80
while (sibling != null ) {
80
81
position += 1 ;
81
- sibling = sibling . getPreviousSibling ( );
82
+ sibling = previousSiblingNotAttribute ( sibling );
82
83
}
83
84
index .add (position );
84
85
85
86
return index ;
86
87
}
87
88
89
+ /**
90
+ * A org.exist.dom.persistent.StoredNode returns attributes of an element as previous siblings of the element's children.
91
+ * This is not compatible with the way xdmNodeAtIndex works, so we need to compensate for this.
92
+ * @param node
93
+ * @return the previous sibling of `node` that is not an attribute.
94
+ */
95
+ private static Node previousSiblingNotAttribute (Node node ) {
96
+ Node sibling = node .getPreviousSibling ();
97
+ if (sibling instanceof Attr ) {
98
+ return null ;
99
+ }
100
+ return sibling ;
101
+ }
102
+
88
103
static XdmNode xdmNodeAtIndex (final XdmNode xdmNode , final List <Integer > index ) {
89
104
if (index .isEmpty ()) {
90
105
return xdmNode ;
You can’t perform that action at this time.
0 commit comments