Using XSLT in Java Applications

As you saw yesterday, JAXP provides a javax.xml.transform.Transformer class that is used to transform XML documents using XSLT. A javax.xml.transform.TransformerFactory is used to create a Transformer object. A new TransformerFactory object is created by the static newInstance() method in the factory class.

The following code creates a new TransformerFactory:

TransformerFactory factory = TransformerFactory.newInstance();

A Transformer object is created by a newTransformer() method in the factory object and optionally takes an XSLT stylesheet as a parameter to the method. The XSLT stylesheet must be accessed using a javax.xml.transform.stream.Source object. A StreamSource object can be constructed from a java.io.InputStream ...

Get Sams Teach Yourself J2EE™ in 21 Days, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.