Whitespace

When processing the source document, an XSLT processor creates a tree of nodes (possibly using a DOM tree: see Chapter 20), including nodes for each text string within and between the markup tags. If the source document contains only whitespace characters between two markup constructs, a text node may be created. But nodes that contain only whitespace will by default then be discarded. In the following example, text nodes will not be created before and after the Para element:

<book>  <para>A paragraph.</para>

  </book>

But it can be desirable to preserve such spaces in some circumstances.

Preserve space

Individual elements can be added to an (initially empty) list of whitespace preserving elements, using the Preserve Space element, ...

Get XML Companion, The, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.