@Override public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { NodeInfo stylesheet = (NodeInfo) arguments[0].head(); NodeInfo node = (NodeInfo) arguments[1].head(); Evaluator eval = SearchBase.getEvaluator(context); XsltCompiler xsltCompiler = eval.getCompiler().getXsltCompiler(); xsltCompiler.setErrorListener(eval.getErrorListener()); try { // TODO: cache compiled xslt somewhere XsltExecutable xsltexec = xsltCompiler.compile(stylesheet); transformer = xsltexec.load(); transformer.setSource(node); transformer.setErrorListener(eval.getErrorListener()); if (arguments.length > 2) { bindParameters(arguments[2]); } XdmDestination dest = new XdmDestination(); transformer.setDestination(dest); transformer.transform(); ArrayList<TransformerException> runtimeErrors = ((TransformErrorListener) transformer.getErrorListener()).getErrors(); if (!runtimeErrors.isEmpty()) { throw new XPathException( runtimeErrors.get(0).getMessage(), runtimeErrors.get(0).getLocator(), runtimeErrors.get(0)); } XdmNode result = dest.getXdmNode(); if (result == null) { return EmptySequence.getInstance(); } return result.getUnderlyingNode(); } catch (SaxonApiException e) { throw new XPathException(e); } }
@Override public void commit(Evaluator eval) { SolrQueryContext context = (SolrQueryContext) eval.getQueryContext(); context.setCommitPending(true); }