Afficher valeur d'une balise avec condition
Bonjour,
J'ai un simple fichier xsl qui afficher la valeur d'une balise d'un fichier xml. la source xsl est la suivante :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| <?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="var1">
Greatest Hits
</xsl:variable>
<html>
<body>
<h1>Music Collection:</h1>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<tr>
<td><xsl:value-of select="catalog/cd [title=$var1]/artist" /></td>
<td> </td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet> |
le fichier xml est le suivant :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?xml version="1.0" encoding="UTF-8"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog> |
je veux afficher la valeur de "artist". Avec cette commande
Code:
<td><xsl:value-of select="catalog/cd [title='Greatest Hits']/artist" /></td>
, je peux avoir le résultat.
Si je change la valeur 'Greatest Hits' par le nom de la variable.. j'ai un résultat vide.
Code:
<xsl:value-of select="catalog/cd [title='$var1']/artist" />
Merci pour votre aide