/** * Compile the function into a UserFunction object, which treats the function body as a single * XPath expression. This involves recursively translating xsl:variable declarations into let * expressions, withe the action part of the let expression containing the rest of the function * body. The UserFunction that is created will be linked from all calls to this function, so * nothing else needs to be done with the result. If there are no calls to it, the compiled * function will be garbage-collected away. * * @param exec the Executable * @param decl this xsl:function declaration * @throws XPathException if a failure occurs */ private void compileAsExpression(Executable exec, Declaration decl) throws XPathException { Expression exp = compileSequenceConstructor(exec, decl, iterateAxis(Axis.CHILD), false); if (exp == null) { exp = Literal.makeEmptySequence(); } else { ExpressionVisitor visitor = makeExpressionVisitor(); exp = exp.simplify(visitor); } if (exec.getConfiguration().isCompileWithTracing()) { TraceExpression trace = new TraceExpression(exp); trace.setConstructType(StandardNames.XSL_FUNCTION); trace.setNamespaceResolver(getNamespaceResolver()); trace.setObjectName(getObjectName()); exp = trace; } UserFunction fn = exec.getConfiguration().newUserFunction(memoFunction); fn.setHostLanguage(Configuration.XSLT); fn.setBody(exp); fn.setFunctionName(getObjectName()); setParameterDefinitions(fn); fn.setResultType(getResultType()); fn.setLineNumber(getLineNumber()); fn.setSystemId(getSystemId()); fn.setStackFrameMap(stackFrameMap); fn.setExecutable(exec); compiledFunction = fn; fixupInstruction(fn); if (memoFunction && !fn.isMemoFunction()) { compileWarning( "Memo functions are not available in Saxon-HE: saxon:memo-function attribute ignored", SaxonErrorCode.SXWN9011); } }