} else {
styleSource = new StreamSource(new File(xsl));
}
sheet = f.newTemplates(styleSource);
} catch (TransformerConfigurationException e) {
XPathException e2 = XPathException.makeXPathException(e);
e2.setIsStaticError(true);
throw e2;
}
if (assertion != null) {
TinyBuilder builder = new TinyBuilder();
builder.setPipelineConfiguration(config.makePipelineConfiguration());
ExpressionPresenter presenter = new ExpressionPresenter(config, builder);
((PreparedStylesheet)sheet).explain(presenter);
presenter.close();
NodeInfo expressionTree = builder.getCurrentRoot();
XPathEvaluator xpe = new XPathEvaluator(config);
XPathExpression exp = xpe.createExpression(assertion);
Boolean bv = (Boolean)exp.evaluateSingle(expressionTree);
if (!bv.booleanValue()) {
System.err.println("** Optimization assertion failed");
presenter = new ExpressionPresenter(config);
((PreparedStylesheet)sheet).explain(presenter);
presenter.close();
throw new XPathException("Expected optimization not performed");
}
}
Transformer inst;
try {
inst = sheet.newTransformer();
} catch (TransformerConfigurationException e) {
XPathException e2 = XPathException.makeXPathException(e);
e2.setIsStaticError(true);
throw e2;
}
if (initialMode != null) {
((Controller)inst).setInitialMode(initialMode);
}
if (initialTemplate != null) {
((Controller)inst).setInitialTemplate(initialTemplate);
}
if (params != null) {
Iterator iter = params.keySet().iterator();
while (iter.hasNext()) {
String name = (String)iter.next();
String value = (String)params.get(name);
inst.setParameter(name, value);
}
}
if ("strict".equals(validationMode)) {
((Controller)inst).setSchemaValidationMode(Validation.STRICT);
} else {
((Controller)inst).setSchemaValidationMode(Validation.STRIP);
}
inst.setURIResolver(factory.getURIResolver());
inst.setErrorListener(errorListener);
((Controller)inst).setRecoveryPolicy(recoverRecoverable ? Configuration.RECOVER_SILENTLY : Configuration.DO_NOT_RECOVER);
// To avoid test results being dependent on the date and time (and timezone), set a fixed
// date and time for the run
//((Controller)inst).setCurrentDateTime(new DateTimeValue("2005-01-01T12:49:30.5+01:00"));
try {
inst.transform(source, sr);
} catch (TransformerException e) {
XPathException e2 = XPathException.makeXPathException(e);
e2.setIsStaticError(false);
throw e2;
}
}