Overriding <xsl:preserve-space> and <xsl:strip-space>
A version of this page is also available for
4/8/2010
Use the xml:space attribute to override the effect of <xsl:strip-space> or <xsl:preserve-space>. When applied to a white-space-only <xsl:text> node within an element otherwise marked to have its spaces stripped or preserved, xml:space indicates whether the white space content contained within the <xsl:text> element should be preserved. For example, even though the <block> elements in the preceding example were specified in the <xsl:strip-space> element list, you can force the preservation of four spaces by including the following in that template rule.
<block><xsl:text xml:space="yes"> </xsl:text></block>
This example is artificial, in that it forces the insertion of white space within the style sheet. It does not restore or preserve white space in the original document. To do that, you must override the default stripping of extraneous white space by setting the preserveWhiteSpace property to TRUE at the time the document is loaded into the Document Object Model (DOM).
See Also
Concepts
Preserving and Stripping White Space
Handling White Space
Controlling White Space with the DOM