}
}
public Expression compile(Executable exec) throws XPathException {
StaticContext env = getStaticContext();
Configuration config = env.getConfiguration();
StringCollator collator = null;
if (collationName != null) {
collator = getPrincipalStylesheet().findCollation(collationName);
if (collator==null) {
compileError("The collation name " + Err.wrap(collationName, Err.URI) + " is not recognized", "XTSE1210");
collator = CodepointCollator.getInstance();
}
if (collator instanceof CodepointCollator) {
// if the user explicitly asks for the codepoint collation, treat it as if they hadn't asked
collator = null;
collationName = null;
} else if (!Configuration.getPlatform().canReturnCollationKeys(collator)) {
compileError("The collation used for xsl:key must be capable of generating collation keys", "XTSE1210");
}
}
if (use==null) {
Expression body = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true);
try {
ExpressionVisitor visitor = makeExpressionVisitor();
use = new Atomizer(body);
use = visitor.simplify(use);
} catch (XPathException e) {
compileError(e);
}
try {
RoleLocator role =
new RoleLocator(RoleLocator.INSTRUCTION, "xsl:key/use", 0);
//role.setSourceLocator(new ExpressionLocation(this));
use = TypeChecker.staticTypeCheck(
use,
SequenceType.makeSequenceType(BuiltInAtomicType.ANY_ATOMIC, StaticProperty.ALLOWS_ZERO_OR_MORE),
false, role, makeExpressionVisitor());
// Do a further check that the use expression makes sense in the context of the match pattern
use = makeExpressionVisitor().typeCheck(use, match.getNodeTest());
} catch (XPathException err) {
compileError(err);
}
}
final TypeHierarchy th = config.getTypeHierarchy();
BuiltInAtomicType useType = (BuiltInAtomicType)use.getItemType(th).getPrimitiveItemType();
if (backwardsCompatibleModeIsEnabled()) {
if (!useType.equals(BuiltInAtomicType.STRING) && !useType.equals(BuiltInAtomicType.UNTYPED_ATOMIC)) {
use = new AtomicSequenceConverter(use, BuiltInAtomicType.STRING);
useType = BuiltInAtomicType.STRING;