public IteratorResult MoveNext(XPathNavigator input) {
switch (this.state) {
case IteratorState.NeedCandidateCurrent:
// If there are no more input nodes, then iteration is complete
if (input == null)
return IteratorResult.NoMoreNodes;
// Save input node as current node
this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, input);
// Scan for additional input nodes within the same document (since they are after navCurrent in docorder)
this.state = IteratorState.HaveCandidateCurrent;
return IteratorResult.NeedInputNode;
case IteratorState.HaveCandidateCurrent:
// If there are no more input nodes,
if (input == null) {
// Then candidate node has been selected, and there are no further input nodes
this.state = IteratorState.HaveCurrentNoNext;
}
else {
// If the input node is in the same document as the current node,
if (this.navCurrent.ComparePosition(input) != XmlNodeOrder.Unknown) {
// Then update the current node and get the next input node
this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, input);
return IteratorResult.NeedInputNode;
}
// Save the input node as navNext
this.navNext = XmlQueryRuntime.SyncToNavigator(this.navNext, input);
this.state = IteratorState.HaveCurrentHaveNext;
}
PushAncestors();
break;
}
if (!this.navStack.IsEmpty) {
while (true) {
// Move to the next matching node that is before the top node on the stack in document order
if (this.filter.MoveToFollowing(this.navCurrent, this.navStack.Peek()))
// Found match
return IteratorResult.HaveCurrentNode;
// Do not include ancestor nodes as part of the preceding axis
this.navCurrent.MoveTo(this.navStack.Pop());
// No more preceding matches possible
if (this.navStack.IsEmpty)
break;
}
}
if (this.state == IteratorState.HaveCurrentNoNext) {
// No more nodes, so iteration is complete
this.state = IteratorState.NeedCandidateCurrent;
return IteratorResult.NoMoreNodes;
}
// Make next node the current node and start trying to find input node greatest in docorder
this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, this.navNext);
this.state = IteratorState.HaveCandidateCurrent;
return IteratorResult.HaveCurrentNode;
}