Tight control on whitespaces in XSLT-generated documents

Continuing from the previous post on the whitespace issues, here are a few rules that you should keep in mind:
  • Whitespace-only text nodes are not copied from the XSLT document into the output document;
  • Text nodes containing non-whitespace characters are copied in their entirety, including any whitespace characters that are copied verbatim. Extra line breaks can easily appear in your output text, more so if you try to apply nice readable format to the source XSLT document.
  • If you want very tight control on the generated output, place the non-whitespace characters only within the xsl:text tags. The contents of the xsl:text tag (which cannot contain any embedded tags) is copied straight into the output document.

The whitespace control is extremely important if you're generating text output with XSLT transformation.

No comments:

Post a Comment