Skip to content

xsl:text

Writes literal text to the result tree.

<xsl:text>Hello, world!</xsl:text>

The main reason to use xsl:text rather than just plain text content is whitespace control: text inside xsl:text is preserved exactly, including leading and trailing whitespace, while plain text in the stylesheet body is subject to whitespace stripping.

If expand-text="yes" is in effect (either on xsl:text itself or inherited from an ancestor), the text content is treated as a Text Value Template — {...} expressions are evaluated and their string values are interpolated.

Attributes

Attribute Description
disable-output-escaping yes to write characters like < and & raw (legacy XSLT 1.0 feature).
expand-text yes to enable Text Value Template expansion in this element’s text.

Examples

Inserting a literal space:

<xsl:value-of select="firstname"/>
<xsl:text> </xsl:text>
<xsl:value-of select="lastname"/>

With Text Value Template expansion:

<xsl:text expand-text="yes">Hello, {$name}!</xsl:text>