XSLT <xsl:otherwise> ਐਲੀਮੈਂਟ

ਪਰਿਭਾਸ਼ਾ ਅਤੇ ਵਰਤੋਂ

<xsl:otherwise> ਐਲੀਮੈਂਟ ਨੇ <xsl:choose> ਐਲੀਮੈਂਟ ਦੀ ਮੂਲਤਬੀ ਵਿਵਹਾਰ ਨੂੰ ਨਿਰਧਾਰਿਤ ਕਰਦਾ ਹੈ।ਜਦੋਂ ਕੋਈ <xsl:when> ਸ਼ਰਤ ਨਾ ਲਾਗੂ ਹੁੰਦਾ ਹੈ ਤਾਂ ਇਹ ਵਿਵਹਾਰ ਲਾਗੂ ਹੁੰਦਾ ਹੈ。

ਗਤੀਸ਼ੀਲਤਾ

<xsl:otherwise>
<!-- Content:template -->
</xsl:otherwise>

ਵਿਸ਼ੇਸ਼ਤਾ

None

ਉਦਾਹਰਣ

ਉਦਾਹਰਣ 1

ਨਿਮਨ ਕੋਡ cd ਦੀ ਕੀਮਤ 30 ਤੋਂ ਉੱਪਰ ਹੋਣ ਉੱਤੇ artist ਸ਼ਾਖਾ ਵਿੱਚ ਪੁਲਾਟੀ ਰੰਗ ਦੇ ਪੱਗਲੇ ਦਿੰਦਾ ਹੈ ਜਦੋਂ ਤੱਕ ਨਹੀਂ ਤਾਂ ਮਾਤਰ artist ਦਾ name ਹੀ ਨਿਕਾਲਦਾ ਹੈ:

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

ਇੱਕ ਨਾਮ "color" ਵਰਗੀ ਵਿਅਕਤੀ ਨੂੰ ਐਲਾਨ ਕਰੋ।ਇਸ ਦਾ ਮੁੱਲ ਮੌਜੂਦਾ ਤੱਤ ਦੇ color ਅਤਰੀਬ ਨੂੰ ਅਤੇਣ ਦਿੱਤਾ ਜਾਵੇਗਾ।ਜੇਕਰ ਮੌਜੂਦਾ ਤੱਤ ਨਾਲ color ਅਤਰੀਬ ਨਹੀਂ ਹੈ ਤਾਂ "color" ਦਾ ਮੁੱਲ "green" ਹੋਵੇਗਾ:

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