text_1-input.xml
<?xml version="1.0"?>
<persons>
<person>
<first-name>Barack</first-name>
<middle-name>Hussein</middle-name>
<last-name>Obama</last-name>
</person>
<person>
<first-name>Hans</first-name>
<middle-name>Christian</middle-name>
<last-name>Andersen</last-name>
</person>
</persons>
text_1-stylesheet.xsl
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output
indent="yes"/>
<xsl:template
match="persons">
<persons>
<xsl:apply-templates/>
</persons>
</xsl:template>
<xsl:template
match="person[1]">
<person>
<xsl:value-of
select="first-name"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="middle-name"/>
<xsl:text> </xsl:text>
<xsl:value-of
select="last-name"/>
</person>
</xsl:template>
<xsl:template
match="person[2]">
<person>
<xsl:value-of
select="concat(first-name, ' ', middle-name, ' ', last-name)"/>
</person>
</xsl:template>
</xsl:stylesheet>
text_1-output.xml
<?xml version="1.0" encoding="UTF-8"?>
<persons>
<person>Barack Hussein Obama</person>
<person>Hans Christian Andersen</person>
</persons>
The most common use of xsl:text is for controling whitespace. The template matching the second person is an alternative way of doing the same thing.
Updated 2009-03-19