UnparsedTextURIResolver unparsedTextURIResolver = runtime.getResolver();
config.setOutputURIResolver(new OutputResolver());
config.setCollectionURIResolver(new CollectionResolver(runtime, defaultCollection, collectionResolver));
XdmDestination result = null;
try {
XsltCompiler compiler = runtime.getProcessor().newXsltCompiler();
compiler.setSchemaAware(processor.isSchemaAware());
XsltExecutable exec = compiler.compile(stylesheet.asSource());
XsltTransformer transformer = exec.load();
for (QName name : params.keySet()) {
RuntimeValue v = params.get(name);
if (runtime.getAllowGeneralExpressions()) {
transformer.setParameter(name, v.getValue());
} else {
transformer.setParameter(name, new XdmAtomicValue(v.getString()));
}
}
if (document != null) {
transformer.setInitialContextNode(document);
}
transformer.setMessageListener(new CatchMessages());
result = new XdmDestination();
transformer.setDestination(result);
if (initialMode != null) {
transformer.setInitialMode(initialMode);
}
if (templateName != null) {
transformer.setInitialTemplate(templateName);
}
if (outputBaseURI != null) {
transformer.setBaseOutputURI(outputBaseURI);
// The following hack works around https://saxonica.plan.io/issues/1724
try {
result.setBaseURI(new URI(outputBaseURI));
} catch (URISyntaxException use) {
// whatever
}
}
transformer.setSchemaValidationMode(ValidationMode.DEFAULT);
transformer.getUnderlyingController().setUnparsedTextURIResolver(unparsedTextURIResolver);
transformer.transform();
} finally {
config.setOutputURIResolver(uriResolver);
config.setCollectionURIResolver(collectionResolver);
}
XdmNode xformed = result.getXdmNode();
// Can be null when nothing is written to the principle result tree...
if (xformed != null) {
if (document != null
&& (xformed.getBaseURI() == null