ایکس ایس ایل تی <xsl:choose> عناصر
- ਪਿਛਲਾ ਪੰਨਾ XSLT <if>
- ਅਗਲਾ ਪੰਨਾ XSLT Apply
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>
ਇਸ ਕੋਡ ਵਿੱਚ CD ਦੀ ਕੀਮਤ 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 Apply