public Source getAssociatedStylesheet(
Source source, String media, String title, String charset)
throws TransformerConfigurationException {
PIGrabber grabber = new PIGrabber();
grabber.setFactory(config);
grabber.setCriteria(media, title, charset);
grabber.setBaseURI(source.getSystemId());
grabber.setURIResolver(config.getURIResolver());
try {
new Sender(config.makePipelineConfiguration()).send(source, grabber);
// this parse will be aborted when the first start tag is found
} catch (XPathException err) {
if (grabber.isTerminated()) {
// do nothing
} else {
throw new TransformerConfigurationException(
"Failed while looking for xml-stylesheet PI", err);
}
}
try {
Source[] sources = grabber.getAssociatedStylesheets();
if (sources==null) {
throw new TransformerConfigurationException(
"No matching <?xml-stylesheet?> processing instruction found");
}
return compositeStylesheet(source.getSystemId(), sources);