The xsl:text element is used to add literal text to the output. This element cannot contain any other XSL elements. It can only contain text.
Normally, any text that occurs in a stylesheet will be copied to the output regardless if it is enclosed by an xsl:text element. However, there are two primary reasons for using the xsl:text element:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />
<xsl:template match="/">
<html>
<body>
<xsl:text>The DevGuru Staff Members are </xsl:text>
<xsl:for-each select="devguru_staff/programmer">
<xsl:value-of select="name" />
<xsl:if test="position()!=last()">
<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>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
The DevGuru Staff Members are Bugs Bunny, Daisy Duck, Minnie Mouse, Pluto, Porky Pig, and Road Runner!
This is the code for xslt_example_text.xsl.
We use the DevGuru Staff List XML file for our example with the following header:
<?xml-stylesheet type="text/xsl" href="xslt_example_text.xsl"?>