Stylesheet organization
The stylesheet does an XML-to-XML copy (called an identity transform) that provides special-case processing for text nodes and processing instructions. The templates used in the stylesheet perform these functions:
-
Root template—Handles the document root, adds a DOCTYPE declaration, and hands off processing to other templates.
-
Match processing instruction nodes—Handles all processing instruction nodes.
-
Match text nodes—Handles all text nodes. This is the heart of the stylesheet, where the normalize-space() function is applied.
-
Match attributes—Handles attributes. Removes attributes added by the parser.
-
Match other nodes (elements and comments)—Identifies elements that preserve whitespace and handles them differently.
-
Keepspace template—Copies elements, preserving all whitespace.
The stylesheet uses an <xsl:output> statement to ensure that the output is not indented.
<xsl:output method="xml" indent="no" xml:space="default"
encoding="UTF-8"/>
For testing purposes, there are two versions of the <xsl:output> statement:
-
The first one contains indent="yes" and is commented out.
-
The second (shown above) contains indent="no".
When you use indent="no", most of the output appears on one line. To debug the transform, you might want to see the output on multiple lines. In that case, uncomment the first <xsl:output> statement and comment out the second one. Just remember to restore the correct form of the <xsl:output> statement before putting your transform into production.
Next Page:
Root template
