एक्सएसएलटी <xsl:कब>
❮ पूर्ण एक्सएसएलटी तत्व संदर्भ
परिभाषा और उपयोग
<xsl: जब> तत्व का उपयोग <xsl:choose> तत्व के लिए एक क्रिया निर्दिष्ट करने के लिए किया जाता है। <xsl:when> एलिमेंट एक एक्सप्रेशन का मूल्यांकन करता है, और अगर यह सही होता है, तो एक क्रिया की जाती है।
नोट: कई सशर्त परीक्षणों को व्यक्त करने के लिए <xsl:when> तत्व का उपयोग <xsl:choose> और <xsl:अन्यथा> के संयोजन में किया जाता है।
वाक्य - विन्यास
<xsl:when
test="boolean-expression">
<!-- Content: template -->
</xsl:when>
गुण
Attribute | Value | Description |
---|---|---|
test | boolean-expression | Required. Specifies a Boolean expression to be tested |
उदाहरण 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>
एक्सएमएल फाइल देखें , एक्सएसएल फाइल देखें और परिणाम देखें ।
उदाहरण 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>
❮ पूर्ण एक्सएसएलटी तत्व संदर्भ