Multiple conditions in XSLT



I have to use XSLT to transform my XML document into a Bootstrap table. I have done it before using PHP and it was quite simple and I'm trying to adapt it in XSLT.


With PHP I did something like this :



while($line = $request->fetch(PDO::FETCH_ASSOC))
{
echo '<tr ';
switch($line["category"])
{
case "Movie" : echo "class='info'";break;
case "Tv show" : echo "class='danger'";break;
case "Music" : echo "class='success'";break;
}
echo ' >';
...
echo "</tr>";
}


I tried to do a similar code in XSLT (not using concatenation because we can't) :



<xsl:for-each select="demands/demand">
<xsl:choose>
<xsl:when test="category = 'Movie'">
<tr class="info">
</xsl:when>
<xsl:when test="category = 'Tv show'">
<tr class="danger">
</xsl:when>
<xsl:when test="categorie = 'Music'">
<tr class="success">
</xsl:when>
</xsl:choose>
...
</tr>
</xsl:for-each>


That doesn't work ("Opening and ending tag mismatch: tr line") because there is only one closing tr tag. Is there any solution to that ? How can I do it the simpliest way ?


Thank's for your help.


No comments:

Post a Comment