एक्सएसएलटी <xsl:if> एलीमेंट

<xsl:if> एलीमेंट का उपयोग XML फ़ाइल की सामग्री के लिए शर्तीय परीक्षण रखने के लिए किया जाता है。

<xsl:if> एलीमेंट

यदि XML फ़ाइल की सामग्री के लिए शर्तीय परीक्षण जोड़ना है, तो XSL दस्तावेज़ में <xsl:if> एलीमेंट जोड़ें。

व्याकरण

<xsl:if test="expression">
  ...
  ...यदि शर्त सही है तो आउटपुट करें...
  ...
</xsl:if>

जहां <xsl:if> एलीमेंट रखना है

यदि शर्तीय परीक्षण जोड़ना है, तो XSL फ़ाइल में <xsl:for-each> एलीमेंट के अंदर <xsl:if> एलीमेंट जोड़ें:

<?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="/">
  <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">
      <xsl:if test="price > 10">
        <tr>
          <td><xsl:value-of select="title"/></td>
          <td><xsl:value-of select="artist"/></td>
        </tr>
      </xsl:if>
      </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>

टिप्पणी:अनिवार्य टेस्ट गुण का मूल्य जोगफल शामिल है。

ऊपरी कोड केवल 10 से अधिक मूल्य वाले सीडी के title और artist एलीमेंट को आउटपुट करेगा。

ऊपरी ट्रांसफॉर्म का परिणाम इस तरह है:

इस एक्सएमएल फ़ाइल को देखेंइस एक्सएसएल फ़ाइल को देखेंपरिणाम देखें