Java Reference
In-Depth Information
TransformerFactory tf = TransformerFactory.newInstance();
StreamSource ssStyleSheet;
ssStyleSheet
=
new
StreamSource(new
FileRead-
er("recipe.xsl"));
Transformer t = tf.newTransformer(ssStyleSheet);
t.setOutputProperty(OutputKeys.METHOD, "html");
t.setOutputProperty(OutputKeys.INDENT, "yes");
Source source = new DOMSource(doc);
Result result = new StreamResult(System.out);
t.transform(source, result);
This excerpt reveals that the output method is set to
html
, and it also reveals that
theresultingHTMLshouldbeindented.However,theoutputisonlypartlyindented,as
shown in
Listing 10-29
.
Listing 10-29.
The HTML equivalent of
Listing 10-1
'
s recipe document
<html>
<head>
<META http-equiv="content-type" content="text/html; char-
set=utf-8">
<title>Recipes</title>
</head>
<body>
<h2>Grilled Cheese Sandwich</h2>
<h3>Ingredients</h3>
<ul>
<li>bread slice (2)</li>
<li>cheese slice</li>
<li>margarine pat (2)</li>
</ul>
<h3>Instructions</h3>Place frying pan on element and select
medium heat. For each bread slice,
smear one pat of margarine on one side of bread slice. Place
cheese slice between bread slices
with margarine-smeared sides away from the cheese. Place
sandwich in frying pan with one
margarine-smeared side in contact with pan. Fry for a