एक्सएसएलटी <xsl: चुनें> तत्व
कई सशर्त परीक्षणों को व्यक्त करने के लिए <xsl:choose> तत्व का उपयोग <xsl:when> और <xsl:अन्यथा> के संयोजन में किया जाता है।
<xsl: चुनें> तत्व
वाक्य - विन्यास
<xsl:choose>
<xsl:when test="expression">
... some output ...
</xsl:when>
<xsl:otherwise>
... some output ....
</xsl:otherwise>
</xsl:choose>
कंडीशन चुनें कहां लगाएं
XML फ़ाइल के विरुद्ध एक से अधिक सशर्त परीक्षण सम्मिलित करने के लिए, XSL फ़ाइल में <xsl:choose>, <xsl:when>, और <xsl:अन्यथा> तत्व जोड़ें:
उदाहरण
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price > 10">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
उपरोक्त कोड "कलाकार" कॉलम में एक गुलाबी पृष्ठभूमि-रंग जोड़ देगा जब सीडी की कीमत 10 से अधिक होगी।
एक और उदाहरण
यहां एक और उदाहरण दिया गया है जिसमें दो <xsl:when> तत्व शामिल हैं:
उदाहरण
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th>Title</th>
<th>Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<xsl:choose>
<xsl:when test="price > 10">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:when test="price > 9">
<td bgcolor="#cccccc">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
ऊपर दिया गया कोड "कलाकार" कॉलम में एक गुलाबी पृष्ठभूमि रंग जोड़ देगा जब सीडी की कीमत 10 से अधिक होगी, और एक ग्रे पृष्ठभूमि-रंग जब सीडी की कीमत 9 से अधिक और कम या 10 के बराबर होगी।