Controlling White Space Using the Style Sheet

MSXML 5.0 SDK

Microsoft XML Core Services (MSXML) 5.0 for Microsoft Office - XSLT Developer's Guide

Controlling White Space Using the Style Sheet

White space only nodes in the XSLT style sheet, as opposed to those in the source document, are stripped by the XSLT processor.

It can be an advantage to have extraneous white space stripped from a style sheet. You can format the style sheet for easy readability and maintenance, knowing that extra tabs, newlines, and so on will not appear in the result tree.

However, this can be a disadvantage when you need white space of a particular kind in the result tree. For example, if you had to insert a blank space in a table cell, you might use the following.

<td> </td>

However, if your style sheet places this sequence of text in the result tree, it will appear as follows.

<td></td>

Not all browsers will display a NULL cell properly.

Use the <xsl:text> element around any white space only text nodes.

<td><xsl:text> </xsl:text></td>

For more information, see Inserting White Space Using <xsl:text>.