Fonction concat() | |
Prend tous les arguments qu'elle contient et les concatène. Tous les arguments qui ne sont pas des chaînes sont convertis en chaînes comme s'ils avaient été traités par la fonction string(). | |
Entrées | |
Deux ou plusieurs chaînes. |
|
Sortie | |
La concaténation de toutes les chaînes d'entrée. |
|
Définie dans | |
XPath section 4.2, Fonctions Chaîne. |
|
Exemple | |
Le fichier XML suivant permet d'illustrer le fonctionnement de la fonction concat() : <?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> La feuille de style utilise la fonction concat() pour créer des noms de fichiers pour plusieurs fichiers JPEG. Les noms de fichiers se composent de plusieurs informations, concaténées par la fonction concat() : <?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> Les résultats suivants ont été générés par la feuille de style : 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 |