NodeInfo first = null;
// Find the first node in ns2 (in document order)
GlobalOrderComparer comparer = GlobalOrderComparer.getInstance();
while (true) {
Item item = ns2.next();
if (item == null) {
if (first == null) {
return ns1;
}
break;
}
if (item instanceof NodeInfo) {
NodeInfo node = (NodeInfo)item;
if (first==null) {
first = node;
} else {
if (comparer.compare(node, first) < 0) {
first = node;
}
}
} else {
XPathException e = new XPathException("Operand of leading() contains an item that is not a node");