| concat() Function | |
| Takes all of its arguments and concatenates them. Any arguments that are not strings are converted to strings as if processed by the string() function. | |
| Inputs | |
|
Two or more strings. |
|
| Output | |
|
The concatenation of all of the input strings. |
|
| Defined in | |
|
XPath section 4.2, String Functions. |
|
| Example | |
|
We'll use this XML file to demonstrate how concat() works: <?xml version="1.0"?> <list> <title>A few of my favorite albums</title> <listitem>A Love Supreme</listitem> <listitem>Beat Crazy</listitem> <listitem>Here Come the Warm Jets</listitem> <listitem>Kind of Blue</listitem> <listitem>London Calling</listitem> <listitem>Remain in Light</listitem> <listitem>The Joshua Tree</listitem> <listitem>The Indestructible Beat of Soweto</listitem> </list> In our stylesheet, we'll use the concat() function to create filenames for various JPEG files. The filenames are composed from several pieces of information, concatenated by the concat() function:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:variable name="newline">
<xsl:text>
</xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="$newline"/>
<xsl:for-each select="list/listitem">
<xsl:text>See the file </xsl:text>
<xsl:value-of select="concat('album', position(), '.jpg')"/>
<xsl:text> to see the title of album #</xsl:text>
<xsl:value-of select="position()"/>
<xsl:value-of select="$newline"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Our stylesheet generates these results: See the file album1.jpg to see the title of album #1 See the file album2.jpg to see the title of album #2 See the file album3.jpg to see the title of album #3 See the file album4.jpg to see the title of album #4 See the file album5.jpg to see the title of album #5 See the file album6.jpg to see the title of album #6 See the file album7.jpg to see the title of album #7 See the file album8.jpg to see the title of album #8 |
|