XSLT <xsl:choose> మూలకం
- పూర్వ పేజీ XSLT <if>
- తదుపరి పేజీ XSLT అప్లై
XSLT <xsl:choose> మూలకం మరియు <xsl:when> మరియు <xsl:otherwise> ను కలిపి బహుళ పరిస్థితి పరికరణను వ్యక్తం చేస్తుంది.
<xsl:choose> మూలకం
సంఘటనలు
<xsl:choose> <xsl:when test="expression"> ... అవుట్పుట్ ... </xsl:when> <xsl:otherwise> ... అవుట్పుట్ ... </xsl:otherwise> </xsl:choose>
ఎక్కడ ఎంపిక పరిస్థితిని పెట్టాలి
XML ఫైలుకు బహుళ పరిస్థితి పరికరణను చేర్చడానికి, XSL ఫైలుకు <xsl:choose>、<xsl:when> మరియు <xsl:otherwise> చేర్చండి:
<?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>
క్యాడీ ధర 10 కంటే ఎక్కువ ఉన్నప్పుడు "Artist" కాలమ్లో పసుపు రంగును నివేదించు కోడ్ ఉంటుంది.
పైన మార్పడులు ఈ విధంగా ఉంటాయి:

మరొక ఉదాహరణ
మరొక రెండు <xsl:when> మూలకాలను కలిగించిన ఉదాహరణ ఇక్కడ ఉంది:
<?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:when test="price > 9"> <td bgcolor="#cccccc"> <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>
ఈ కోడ్ CD ధర 10 కంటే ఎక్కువ ఉన్నప్పుడు "Artist" అంశానికి పసుపు రంగు బ్యాక్గ్రౌండ్ రంగును జోడిస్తుంది, మరియు CD ధర 9 కంటే ఎక్కువ మరియు 10 కంటే తక్కువ ఉన్నప్పుడు "Artist" అంశానికి కాలినర్ రంగు బ్యాక్గ్రౌండ్ రంగును జోడిస్తుంది.
పైన మార్పడులు ఈ విధంగా ఉంటాయి:

- పూర్వ పేజీ XSLT <if>
- తదుపరి పేజీ XSLT అప్లై