Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Functions operating on strings (11/15) >

Joining strings with concat()

The function concat() concatenates two and more arguments (which are cast to string before concatenation).

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <xxx>
                        <xsl:value-of  select="concat(ddd,eee)"/>
                  </xxx>
                  <yyy>
                        <xsl:value-of  select="concat(ccc,' ',ddd,' ',eee)"/>
                  </yyy>
                  <zzz>
                        <xsl:value-of  select="concat(name(*[3]),':',*[3])"/>
                  </zzz>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>How</bbb>
            <ccc>do</ccc>
            <ddd>you</ddd>
            <eee>do</eee>
      </aaa>
Output

      <xxx>youdo</xxx>
      <yyy>do you do</yyy>
      <zzz>ddd:you</zzz>


Previous chapter: Arithmetics
Next chapter: Transforming strings with regular expressions
Previous page: Normalization of whitespace characters in a string with normalize-space function
Next page: Joining strings with string-join