xsl:text

  1. text_1-input.xml

  2. <?xml version="1.0"?>
  3. <persons>
  4.   <person>
  5.     <first-name>Barack</first-name>
  6.     <middle-name>Hussein</middle-name>
  7.     <last-name>Obama</last-name>
  8.   </person>
  9.   <person>
  10.     <first-name>Hans</first-name>
  11.     <middle-name>Christian</middle-name>
  12.     <last-name>Andersen</last-name>
  13.   </person>
  14. </persons>
  1. text_1-stylesheet.xsl

  2. <?xml version="1.0"?>
  3. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  4.   <xsl:output indent="yes"/>
  5.   <xsl:template match="persons">
  6.     <persons>
  7.       <xsl:apply-templates/>
  8.     </persons>
  9.   </xsl:template>
  10.   <xsl:template match="person[1]">
  11.     <person>
  12.       <xsl:value-of select="first-name"/>
  13.       <xsl:text> </xsl:text>
  14.       <xsl:value-of select="middle-name"/>
  15.       <xsl:text> </xsl:text>
  16.       <xsl:value-of select="last-name"/>
  17.     </person>
  18.   </xsl:template>
  19.   <xsl:template match="person[2]">
  20.     <person>
  21.       <xsl:value-of select="concat(first-name, ' ', middle-name, ' ', last-name)"/>
  22.     </person>
  23.   </xsl:template>
  24. </xsl:stylesheet>
  1. text_1-output.xml

  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <persons>
  4.   <person>Barack Hussein Obama</person>
  5.   <person>Hans Christian Andersen</person>
  6. </persons>

Comment

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