1 package net.sf.saxon.instruct; 2 import net.sf.saxon.Controller; 3 import net.sf.saxon.expr.XPathContext; 4 import net.sf.saxon.expr.XPathContextMajor; 5 import net.sf.saxon.om.Item; 6 import net.sf.saxon.om.NodeInfo; 7 import net.sf.saxon.style.StandardNames; 8 import net.sf.saxon.trans.DynamicError; 9 import net.sf.saxon.trans.Mode; 10 import net.sf.saxon.trans.XPathException; 11 12 15 16 public class NextMatch extends ApplyImports { 17 18 public NextMatch(boolean backwardsCompatible) { 19 super(backwardsCompatible); 20 } 21 22 25 26 public int getInstructionNameCode() { 27 return StandardNames.XSL_NEXT_MATCH; 28 } 29 30 public TailCall processLeavingTail(XPathContext context) throws XPathException { 31 32 Controller controller = context.getController(); 33 34 36 ParameterSet params = assembleParams(context, actualParams); 37 ParameterSet tunnels = assembleTunnelParams(context, tunnelParams); 38 39 Template currentTemplate = context.getCurrentTemplate(); 40 if (currentTemplate==null) { 41 DynamicError e = new DynamicError("There is no current template rule"); 42 e.setXPathContext(context); 43 e.setErrorCode("XTDE0560"); 44 throw e; 45 } 46 Mode mode = context.getCurrentMode(); 47 if (mode == null) { 48 mode = controller.getRuleManager().getMode(Mode.DEFAULT_MODE); 49 } 50 if (context.getCurrentIterator()==null) { 51 DynamicError e = new DynamicError("There is no context item"); 52 e.setXPathContext(context); 53 e.setErrorCode("XTDE0565"); 54 throw e; 55 } 56 Item currentItem = context.getCurrentIterator().current(); 57 if (!(currentItem instanceof NodeInfo)) { 58 DynamicError e = new DynamicError("Cannot call xsl:next-match when context item is not a node"); 59 e.setXPathContext(context); 60 e.setErrorCode("XTDE0565"); 61 throw e; 62 } 63 NodeInfo node = (NodeInfo)currentItem; 64 Template nh = controller.getRuleManager().getNextMatchHandler(node, mode, currentTemplate, context); 65 66 if (nh==null) { ApplyTemplates.defaultAction(node, params, tunnels, context, false, getLocationId()); 68 } else { 69 XPathContextMajor c2 = context.newContext(); 70 c2.setOrigin(this); 71 c2.openStackFrame(nh.getStackFrameMap()); 72 c2.setLocalParameters(params); 73 c2.setTunnelParameters(tunnels); 74 nh.process(c2); 75 } 76 return null; 77 } 78 } 79 80 | Popular Tags |