public Sequence selectDescendants(MemoryNodeSet descendants) {
sortInDocumentOrder();
final ValueSequence nodes = new ValueSequence(true);
nodes.keepUnOrdered(keepUnOrdered);
for (int i = 0; i <= size; i++) {
final NodeImpl node = (NodeImpl) values[i];
for (int j = 0; j < descendants.size(); j++) {
final NodeImpl descendant = descendants.get(j);
if (descendant.getNodeId().isDescendantOrSelfOf(node.getNodeId()))
{nodes.add(node);}
}
}
return nodes;
}