XSLT <xsl:choose> మెటావేర్

నిర్వచనం మరియు వినియోగం

<xsl:choose> కాలిపెట్టి <xsl:when> మరియు <xsl:otherwise> కాలిపెట్టి బహుళ పరిస్థితి పరికరణలను వ్యక్తం చేయవచ్చు.

ఎటువంటి <xsl:when> నిజం కాదు ఉంటే <xsl:otherwise> కంటెంట్ ప్రాసెస్ చేయండి.

ఎటువంటి <xsl:when> నిజం కాదు మరియు <xsl:otherwise> కాలిపెట్టబడలేదు ఉన్నప్పుడు ఏ కంటెంట్ కలిగించబడదు.

సలహా:సాధారణ పరిస్థితి పరికరణకు ముందుకు <xsl:if> కాలిపెట్టండి.

విధానం

<xsl:choose>
<!-- Content:(xsl:when+,xsl:otherwise?) -->
</xsl:choose>

అంశం

కాని

ప్రకారం

ఉదాహరణ 1

క్రింది కోడ్ సిడి ధర అధికంగా 10 ఉన్నప్పుడు 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">
      <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" వారిబడిన వ్యవకారణాన్ని పేర్కొనండి. ఈ వ్యవకారణం యొక్క విలువను current అంశానికి color అంశంలో అందించండి. current అంశంలో color అంశం లేకపోతే, color యొక్క విలువ గ్రీన్ ఉంటుంది:

<xsl:variable name="color">
  <xsl:choose>
    <xsl:when test="@color">
      <xsl:value-of select="@color"/>
    </xsl:when>  
    <xsl:otherwise>గ్రీన్</xsl:otherwise>
  </xsl:choose>
</xsl:variable>