public XPathExpression createExpression(String expression) throws XPathException {
Expression exp = ExpressionTool.make(expression, staticContext, 0, -1, 1, false);
exp.setContainer(staticContext);
ExpressionVisitor visitor = ExpressionVisitor.make(staticContext);
visitor.setExecutable(getExecutable());
exp = visitor.typeCheck(exp, Type.ITEM_TYPE);
exp = visitor.optimize(exp, Type.ITEM_TYPE);
SlotManager map = staticContext.getStackFrameMap();
int numberOfExternalVariables = map.getNumberOfVariables();
ExpressionTool.allocateSlots(exp, numberOfExternalVariables, map);
XPathExpression xpe = new XPathExpression(this, exp);