Download The Java™ Web Services Tutorial

Transcript
338
XML STYLESHEET LANGUAGE FOR TRANSFORMATIONS
This instruction tells XSL to remove any text nodes under SECT elements that
contain nothing but whitespace. Nodes that contain text other than whitespace
will not be affected, and other kinds of nodes are not affected.
Now, when you run the program, the result looks like this:
<html>
<body>
<h1 align="center">A Sample Article</h1>
<h2>The First Major Section
</h2>
<p>This section will introduce a subsection.</p>
<h3>The Subsection Heading
</h3>
<p>This is the text of the subsection.
</p>
</body>
</html>
That’s quite an improvement. There are still newline characters and white space
after the headings, but those come from the way the XML is written:
<SECT>The First Major Section
____<PARA>This section will introduce a subsection.</PARA>
^^^^
Here, you can see that the section heading ends with a newline and indentation
space, before the PARA entry starts. That’s not a big worry, because the browsers
that will process the HTML routinely compress and ignore the excess space. But
there is still one more formatting tool at our disposal.
Note: The stylesheet described here is article1c.xsl. The result is
stylizer1c.html. (The browser-displayable versions are article1c-xsl.html
and stylizer1c-src.html.)