XSLT 元素
నిర్వచనం మరియు ఉపయోగం
<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
CD యొక్క ధర 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 యొక్క విలువ అని "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>