if (xml != null) {
source = buildSource(xml, validationMode);
if (initialContextPath != null) {
DocumentInfo doc = config.buildDocument(source);
XPathEvaluator xpe = new XPathEvaluator(config);
XPathExpression expr = xpe.createExpression(initialContextPath);
source = (NodeInfo)expr.evaluateSingle(doc);
}
}
Templates sheet;
try {
Source styleSource;
if (useAssociated) {
styleSource = f.getAssociatedStylesheet(source, null, null, null);
} 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();