Whitespace

  • Whitespace between XML elements is treated as a node containing only whitespace
  • Whitespace within a text value is part of the value and is not represented by a whitespace node
  • Whitespace nodes in an XSLT document are ignored
Whitespace characters
  • Space:  
  • Tab: 	
  • Carriage return: 
  • New line: 

Non-whitespace characters
  • Non-breaking space:     ( )

xsl:strip-space

<xsl:strip-space elements="..."/>
  • Removes whitespace nodes
  • elements attribute: Whitespace-separated list of elements
<xsl:strip-space elements="*"/>

xsl:preserve-space

<xsl:preserve-space elements="..."/>
  • Keeps whitespace nodes
  • elements attribute: Whitespace-separated list of elements
  • Whether preserve-space overrides strip-space or vice-versa is determined by which has the greater specifity:
name, ns:name         0
ns:* -0.25
* -0.5

xml:space

... xml:space="<preserve,strip,default>" ...
  • Attribute
  • Overrides strip-space and preserve-space (unless default is specified)

normalize-space()

normalize-space(...)
  • Function
  • Removes redundant whitespace
  • Converts all sequences of whitespace to a single blankspace
  • Used in select expressions
<xsl:value-of select="normalize-space(.)"/>