public IteratorResult MoveNext(XPathNavigator input) {
if (this.state != IteratorState.NeedDescendant) {
if (input == null)
return IteratorResult.NoMoreNodes;
// Descendants of the input node will be duplicates if the input node is in the subtree
// of the previous root.
if (this.state != IteratorState.NoPrevious && this.navRoot.IsDescendant(input))
return IteratorResult.NeedInputNode;
// Save input node as current node and end of input's tree in navEnd
this.navCurrent = XmlQueryRuntime.SyncToNavigator(this.navCurrent, input);
this.navRoot = XmlQueryRuntime.SyncToNavigator(this.navRoot, input);
this.navEnd = XmlQueryRuntime.SyncToNavigator(this.navEnd, input);
this.navEnd.MoveToNonDescendant();
this.state = IteratorState.NeedDescendant;
// If self node matches, then return it
if (this.orSelf && !this.filter.IsFiltered(input))
return IteratorResult.HaveCurrentNode;
}
if (this.filter.MoveToFollowing(this.navCurrent, this.navEnd))
return IteratorResult.HaveCurrentNode;
// No more descendants, so transition to NeedCurrent state and get the next input node
this.state = IteratorState.NeedCurrent;
return IteratorResult.NeedInputNode;
}