ایکس ایس ال ٹی <xsl:if> علامت

ਵਿਆਖਿਆ ਅਤੇ ਵਰਤੋਂ

<xsl:if> ਵਿੱਚ ਇੱਕ ਟੈਮਪਲੇਟ ਹੈ ਜੋ ਸਿਰਫ ਨਿਰਧਾਰਿਤ ਸ਼ਰਤ ਪੂਰਾ ਹੋਣ ਤਾਂ ਲਾਗੂ ਹੁੰਦਾ ਹੈ。

ਸੁਝਾਅ: <xsl:choose> ਨਾਲ <xsl:when> ਅਤੇ <xsl:otherwise> ਦੇ ਨਾਲ ਵਰਤਣ ਨਾਲ ਬਹੁਧਰਣ ਟੈਸਟ ਕਰਨ ਨੂੰ ਪ੍ਰਗਟ ਕਰੋ!

ਗਰੰਥ

<xsl:if
test="expression">
<!-- Content: template -->
</xsl:if>

ਵਿਸ਼ੇਸ਼ਤਾ

ਵਿਸ਼ੇਸ਼ਤਾ ਮੁੱਲ ਵਰਣਨ
test expression ਲਾਜ਼ਮੀ। ਟੈਸਟ ਕਰਨ ਵਾਲੀ ਸ਼ਰਤ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰੋ。

ਉਦਾਹਰਣ

ਉਦਾਹਰਣ 1

ਜਦੋਂ CD ਦੀ ਕੀਮਤ 10 ਤੋਂ ਉੱਪਰ ਹੁੰਦੀ ਹੈ ਤਾਂ title ਅਤੇ artist ਦੇ ਮੁੱਲ ਚੁਣੋ:

<?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>

XML ਫਾਈਲ ਦੇਖੋXSL ਫਾਈਲ ਦੇਖੋਨਤੀਜੇ ਦੇਖੋ

ਉਦਾਹਰਣ 2

ਹਰੇਕ CD ਦੇ ਸਿਰਲੇਖ ਨੂੰ ਦਿਸਾਓ। ਜੇਕਰ ਆਖਰੀ ਜਾਂ ਆਖਰੀ ਦੂਜੀ CD ਨਹੀਂ ਹੈ ਤਾਂ ਹਰੇਕ CD-title ਵਿਚਕਾਰ ", " ਜੋੜੋ। ਜੇਕਰ ਆਖਰੀ CD ਹੈ ਤਾਂ ਸਿਰਲੇਖ ਦੇ ਬਾਅਦ "!" ਜੋੜੋ। ਜੇਕਰ ਆਖਰੀ ਦੂਜੀ CD ਹੈ ਤਾਂ ਉਸ ਦੇ ਬਾਅਦ ", and " ਜੋੜੋ:

<?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>
    <p>Titles:
    <xsl:for-each select="catalog/cd">
      <xsl:value-of select="title"/>
      <xsl:if test="position()!=last()">
        <xsl:text>, </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()-1">
        <xsl:text> and </xsl:text>
      </xsl:if>
      <xsl:if test="position()=last()">
        <xsl:text>!</xsl:text>
      </xsl:if>
    </xsl:for-each>
    </p>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>