public abstract Source getAssociatedStylesheet(Source xmlDocument, String media, String title, String charset)
throws TransformerConfigurationException;
This method reads the XML document indicated by the first argument, and looks in its prolog for the stylesheet that matches the criteria given in the other three arguments.
If any of these are null, it ignores that criterion.
Loads the stylesheet matching
the criteria into a JAXP
Source
object and returns it.
Use the TransformerFactory.newTransformer()
object to convert this Source
into a
Transformer
object.
Throws a TransformerConfigurationException
if there is no
xml-stylesheet
processing instruction
pointing to an XSLT stylesheet
matching the specified criteria.
// The InputStream in contains the XML document to be transformed try { Source inputDocument = new StreamSource(in); TransformerFactory xformFactory = TransformerFactory.newInstance(); Source xsl = xformFactory.getAssociatedStyleSheet(inputDocument, "print", null, null); Transformer stylesheet = xformFactory.newTransformer(xsl); Result outputDocument = new StreamResult(out); stylesheet.transform(inputDocument, outputDocument); } catch (TransformerConfigurationException e) { System.err.println("Problem with the xml-stylesheet processing instruction"); } catch (TransformerException e) { System.err.println("Problem with the stylesheet"); }