August 2001
Intermediate to advanced
480 pages
11h 16m
English
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.
stringconcat(stringstringstring*)
Two or more strings.
The concatenation of all of the input strings.
XPath section 4.2, String Functions.
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"/> ...