Controlling the Contents of the Result Document

This section highlights some of the XSLT instructions you can specify in a stylesheet to control the contents of the result document. This section discusses the following topics:

Specifying Result Formatting

In a stylesheet, you can specify that the XSLT processor should format the result as XML, HTML, or text. Table 32 describes the XSLT processor output for each alternative:

Result Format
XSLT Processor Output
XML
Well-formed XML.
HTML
Recognized HTML tags and attributes that are formatted according to the HTML 4.0 specification. Most browsers should be able to correctly interpret the result. It is your responsibility to ensure that the result is well-formed HTML. For example, <BR> elements should not have child nodes.
Text
All text nodes in the result in document order.
Table 32. Output Based on Result Format

See xsl:output for information about specifying formatting in a stylesheet.

Creating New Nodes in the Result Document

The simplest way to create new nodes in a result document is to specify them as literal result elements or literal result text in a stylesheet template. For example:

<xsl:template match="/">
               

              
<html><head></head><body><table>
                   
<tr><th>Title</th><th>Author</th><th>Price</th></tr>
                   
...
                   
</table></body></html>
                   

                
</xsl-template>

This template creates many nodes in the result document that were not in the source document.

You can also use XSLT instructions to create new nodes. Typically, you use XSLT instructions when you need to compute the name or value of the node. You can find information about using the following instructions in the XSLT Instructions Quick Reference:

You can use the xsl:value-of instruction to provide the contents for a new node. You can also create a new node by copying the current node from the source document to the result document. The current node is the node for which the XSLT processor instantiates a template. See xsl:copy.

Controlling White Space in the Result

For readability, XML documents (both source documents and stylesheets) often include extra white space. White space in XML documents includes spaces, tabs, and new-line characters. Because this white space is for readability, it receives special treatment.

Text nodes that contain only white space are

  • Preserved as normal text nodes in a source document
  • Ignored in a stylesheet, unless the parent node is xsl:text
Significant white space

Stylus Studio recommends that you specify xsl:text in a stylesheet whenever you want to create significant white space in the result. Significant white space is white space that you want to appear in the result in exactly the way that you specify.

To obtain white space for readability during output formatting, specify the xsl:output instruction with the indent attribute. Default values are yes for HTML, and no for XML. With Stylus Studio, you can select the Indent check box on the Params/Other tab to display indented output instead of one long string. Note that the value of the indent attribute, if specified in the stylesheet, has precedence over the Indent option.

 
Free Stylus Studio XML Training: