XSLT <xsl:text> element

Definition and Usage

The <xsl:text> element is used to write text to the output, that is, to generate text nodes through the stylesheet.

Tip:This element can contain text, entity references, and #PCDATA.

Syntax

<xsl:text disable-output-escaping="yes|no">
  <!-- Content:#PCDATA -->
</xsl:text>

Attribute

Attribute Value Description
disable-output-escaping
  • yes
  • no

Optional. The default value is "no".

If the value is "yes", the text node generated by instantiating the <xsl:text> element will not be escaped when output.

For example, if set to "yes", "<" will not be converted.

If set to "no", it is output as "<".

Netscape 6 does not support this attribute.

Instance

Example 1

Display each CD's title. If it is not the last or second-to-last CD, insert ", " between each cd-title. If it is the last CD, add "!" after the title. If it is the second-to-last CD, add ", and " after the title:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
    <h2>My CD Collection</h2>
    <p>Titles:
    <xsl:for-each select="catalog/cd">
      <xsl:value-of select="title"/>
      <xsl:if test="position() < last()-1">
        <xsl:text>, </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()-1">
        <xsl:text>, and </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()">
        <xsl:text>!</xsl:text>
      </xsl:if>
    </xsl:for-each>
    </p>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>