Using XSLT in Java Applications

The second method of using XSLT is used more often when XML data must be transformed by a Java application. 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 requires a stylesheet as a parameter to the method. The stylesheet must be accessed using a javax.xml.transform.stream.Source ...

Get Sams Teach Yourself J2EE™ in 21 Days now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.