Mode mode,
ParameterSet parameters,
ParameterSet tunnelParameters,
XPathContextMajor context)
throws XPathException {
Controller controller = context.getController();
TailCall tc = null;
XPathContextMajor c2 = context;
// Iterate over this sequence
if (controller.isTracing()) {
c2.setCurrentIterator(iterator);
c2.setCurrentMode(mode);
while(true) {
// process any tail calls returned from previous nodes
while (tc != null) {
tc = tc.processLeavingTail(c2);
}
NodeInfo node = (NodeInfo)iterator.next();
// We can assume it's a node - we did static type checking
if (node == null) break;
// find the node handler [i.e., the template rule] for this node
Template eh = controller.getRuleManager().getTemplateRule(node, mode, c2);
if (eh==null) { // Use the default action for the node
// No need to open a new stack frame!
defaultAction(node, parameters, tunnelParameters, c2);
} else {
if (tunnelParameters != null || eh.needsStackFrame()) {
TraceListener traceListener = controller.getTraceListener();
c2.setLocalParameters(parameters);
c2.setTunnelParameters(tunnelParameters);
c2.openStackFrame(eh.getStackFrameMap());
traceListener.startCurrentItem(node);
tc = eh.processLeavingTail(c2);
traceListener.endCurrentItem(node);
} else {
TraceListener traceListener = controller.getTraceListener();
traceListener.startCurrentItem(node);
tc = eh.processLeavingTail(c2);
traceListener.endCurrentItem(node);
}
}
}
} else { // not tracing
c2.setCurrentIterator(iterator);
c2.setCurrentMode(mode);
while(true) {
// process any tail calls returned from previous nodes
while (tc != null) {
tc = tc.processLeavingTail(c2);
}
NodeInfo node = (NodeInfo)iterator.next();
// We can assume it's a node - we did static type checking
if (node == null) break;
// find the template rule for this node
Template eh = controller.getRuleManager().getTemplateRule(node, mode, c2);
if (eh==null) { // Use the default action for the node
// No need to open a new stack frame!
defaultAction(node, parameters, tunnelParameters, c2);