The xml-stylesheet processing instruction

public abstract Source getAssociatedStylesheet(Source xmlDocument, String media, String title, String charset) throws TransformerConfigurationException;

// 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"); 
}

Previous | Next | Top | Cafe con Leche

Copyright 2000-2003 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified January 12, 2003