/** Simplify: add a third implicit argument, the context document */
 public Expression simplify(StaticContext env) throws XPathException {
   if (!internal && !(env instanceof ExpressionContext)) {
     throw new StaticError(
         "The key() function is available only in XPath expressions within an XSLT stylesheet");
   }
   KeyFn f = (KeyFn) super.simplify(env);
   if (argument.length == 2) {
     f.addContextDocumentArgument(2, "key");
   }
   return f;
 }
 /** Non-standard constructor to create an internal call on key() with a known key fingerprint */
 public static KeyFn internalKeyCall(
     NamePool pool, int fingerprint, String name, Expression value, Expression doc) {
   KeyFn k = new KeyFn();
   Expression[] arguments = {new StringValue(name), value, doc};
   k.argument = arguments;
   k.keyFingerprint = fingerprint;
   k.checked = true;
   k.internal = true;
   k.setDetails(StandardFunction.getFunction("key", 3));
   k.setFunctionNameCode(pool.allocate("fn", NamespaceConstant.FN, "key"));
   k.adoptChildExpression(value);
   k.adoptChildExpression(doc);
   return k;
 }