SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
Handling Source Documents
| Source Documents on the Command Line
| Saxon and XML 1.1
| JAXP Source Types
| Third-party Object Models: DOM, JDOM, and XOM
| Choosing a Tree Model
| The PTree File Format
| Validation of Source Documents
» | Whitespace Stripping in Source Documents
| Serial Processing of Large Documents
XML Schema Processing
The XPath API
Saxon on .NET
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# Whitespace Stripping in Source Documents

A number of factors combine to determine whether whitespace-only text nodes in the source document are visible to the user-written XSLT or XQuery code.

By default, if there is a DTD or schema, then ignorable whitespace is stripped from any source document loaded from a `StreamSource` or `SAXSource`. Ignorable whitespace is defined as the whitespace that appears separating the child elements in element declared to have element-only content. This whitespace is removed regardless of any `xml:space` attributes in the source document.

This represents an incompatible change in Saxon 8.6 relative to previous versions; the change has been made because this is now the standard approach defined in the W3C data model document.

It is possible to change this default behavior in several ways.

- From the Transform or Query command line, options are available: -sall strips all whitespace text nodes, -snone strips no whitespace text nodes, and -signorable strips ignorable whitespace text nodes only (this is the default).

- If the -p option is used on the command line, then query parameters are recognized in the URI passed to the `document()` or `doc()` function. The parameter `strip-space=yes` strips all whitespace text nodes, `strip-space=no` strips no whitespace text nodes, and `strip-space=ignorable` strips ignorable whitespace text nodes only. This overrides anything specified on the command line.

- Options corresponding to the above can also be set on the `TransformerFactory` object or on the `Configuration`. These settings are global.

Whitespace stripping that is specified in any of the above ways occurs only if the source document is parsed: that is, if it supplied as a JAXP `StreamSource` or `SAXSource`.

This whitespace stripping is additional (and prior) to any stripping carried out as a result of the `xsl:strip-space` declaration in the stylesheet.

Next