Click to return to the XML (Extensible Markup Language) home page    
Generating More Sophistic...     Advanced XSL Features    
Web Workshop  |  XML (Extensible Markup Language)

Controlling White Space


By default, white space handling during transformation should produce decent HTML output, but occasionally some white space tweaking might be necessary. Since the white space in the result is based on white space in the style sheet, adding or removing white space in a template can affect the output.

Space between tags in the template becomes new lines in the output except for some tags in the XSL namespace. White space in the source document is normalized—multiple spaces are collapsed and white-space-only text blocks are removed.

The xml:space attribute is honored in both the source document and style sheet. All text portions of source marked xml:space="preserve" are passed verbatim to the style sheet for processing, including the white space between tags. All text portions of the style sheet marked xml:space="preserve" are output verbatim. CDATA sections in source and style sheet also preserve white space.

The following table shows the available remedies for white space problems.

Problem Solution
Template inserts too much white space in output. Remove white space from template.
Necessary white space from style sheet is lost. Specify xml:space="preserve" in the template (on xsl or output elements).
Necessary white space from source is lost. Specify xml:space="preserve" in the source document.

The Microsoft® Internet Explorer 5 XSL Processor does not implement the complete set of functions found in the December 1998 XSL Working Draft.

The XSL Working Draft describes the indent-result attribute, which allows the XSL processor to retain some white space from the source or style sheet for purposes of maintaining human-readable output. Internet Explorer 5 supports only the value of "yes", and defaults to this value.



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.