final Expression collationExp = argument[getNumberOfArguments() - 1];
final Value collationVal = (collationExp instanceof Literal ? ((Literal)collationExp).getValue() : null);
if (collationVal instanceof AtomicValue) {
// Collation is supplied as a constant
String collationName = collationVal.getStringValue();
URI collationURI;
try {
collationURI = new URI(collationName, true);
if (!collationURI.isAbsolute()) {
saveBaseURI(env, true);
if (expressionBaseURI == null) {
XPathException err = new XPathException("The collation name is a relative URI, but the base URI is unknown");
err.setErrorCode("XPST0001");
err.setIsStaticError(true);
err.setLocator(this.getSourceLocator());
throw err;
}
URI base = expressionBaseURI;
collationURI = base.resolve(collationURI.toString());
collationName = collationURI.toString();
}
} catch (URI.URISyntaxException e) {
XPathException err = new XPathException("Collation name '" + collationName + "' is not a valid URI");
err.setErrorCode("FOCH0002");