Applying an XSLT Style Sheet
Now that you know how to create a JSP and load DOM documents, you are ready to apply style sheets to the documents. You have already seen how to use the TransformerFactory to create a Transformer object, so the only missing piece of the puzzle is how you tell the Transformer about your style sheet.
As it turns out, you just need to supply a Source (StreamSource, DOMSource, and so on) when you create the Transformer. For example, if you have a style sheet in /home/mark/style.xsl, you create the Transformer this way:
Transformer trans = tf.newTransformer( new StreamSource(new File(“/home/mark/style.xsl”)));
Listing 10.7 shows a JSP that applies a style sheet to an XML document and displays HTML output. Notice that ...
Get Special Edition Using XSLT 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.