एक्सएसएलटी <xsl:अन्यथा>
❮ पूर्ण एक्सएसएलटी तत्व संदर्भ
परिभाषा और उपयोग
<xsl:अन्यथा> तत्व <xsl:choose> तत्व के लिए एक डिफ़ॉल्ट क्रिया निर्दिष्ट करता है। यह कार्रवाई तब होगी जब <xsl:when> शर्तों में से कोई भी लागू न हो।
वाक्य - विन्यास
<xsl:otherwise>
<!-- Content:template -->
</xsl:otherwise>
गुण
कोई नहीं
उदाहरण 1
नीचे दिया गया कोड कलाकार कॉलम में एक गुलाबी पृष्ठभूमि-रंग जोड़ देगा जब सीडी की कीमत 10 से अधिक होगी, अन्यथा यह सिर्फ कलाकार का नाम प्रिंट करेगा:
<?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>
XML फ़ाइल देखें , XSL फ़ाइल देखें , और परिणाम देखें
उदाहरण 2
"रंग" नामक एक चर घोषित करें। इसके मान को वर्तमान तत्व की रंग विशेषता पर सेट करें। यदि वर्तमान तत्व में कोई रंग विशेषता नहीं है, तो "रंग" का मान "हरा" होगा:
<xsl:variable name="color">
<xsl:choose>
<xsl:when test="@color">
<xsl:value-of select="@color"/>
</xsl:when>
<xsl:otherwise>green</xsl:otherwise>
</xsl:choose>
</xsl:variable>
❮ पूर्ण एक्सएसएलटी तत्व संदर्भ