O'Reilly logo

Special Edition Using XSLT by Michael Floyd

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required