public Value evaluate (Context parentContext, String expr) throws Exception { try { StringBuffer sb = new StringBuffer(); Matcher matcher = PARAM_PATTERN.matcher(expr); while(matcher.find()) { String match = matcher.group(1); if(isIncludeParam(match)) { matcher.appendReplacement(sb, "pfx:__incparam('" + match + "')"); } else { matcher.appendReplacement(sb, "\\$" + match); } } matcher.appendTail(sb); expr = sb.toString(); Context context = parentContext.newContext(); context.setContextNode((NodeInfo)contextNode); context.setPosition(contextNodePosition); context.setCurrentNode((NodeInfo)contextNode); context.setLast(contextNodeLast); return Extensions.evaluate(context, expr); } catch (Exception x) { ExtensionFunctionUtils.setExtensionFunctionError(x); throw x; } }
public List<Node> select(Node context, String xpath) throws TransformerException { List<Node> result; result = new ArrayList<Node>(); NodeInfo cNode = (NodeInfo) context; Expression exp = Expression.make(xpath, new StandaloneContext()); Context ctx = new Context(); ctx.setContextNode(cNode); ctx.setPosition(1); ctx.setLast(1); NodeSetValue nodeSet = exp.evaluateAsNodeSet(ctx); NodeEnumeration enm = nodeSet.enumerate(); while (enm.hasMoreElements()) { result.add((Node)enm.nextElement()); } return result; }
public boolean test(Node context, String test) throws TransformerException { NodeInfo cNode = (NodeInfo) context; Expression exp = Expression.make(test, new StandaloneContext()); Context ctx = new Context(); ctx.setContextNode(cNode); ctx.setPosition(1); ctx.setLast(1); return exp.evaluateAsBoolean(ctx); }
public static void renderStart(Context saxonContext, RenderContextSaxon1 renderContext) throws Exception { try { if(renderContext.getContextNode() != null) { saxonContext.setContextNode((NodeInfo)renderContext.getContextNode()); } if(renderContext.getOutputter() != null) { saxonContext.getController().resetOutputDestination(renderContext.getOutputter()); } } catch(Exception x) { ExtensionFunctionUtils.setExtensionFunctionError(x); throw x; } }