Give an example of XSL file with choose condition?
Answer:
Using choose conditon in XSL file we can add some multi conditional test cases. Example: <?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>Book Collection</h2> <table border="1"> <tr bgcolor="#9acd32"> <th>Title</th> <th>Author</th> </tr> <xsl:for-each select="catalog/book"> <tr> <td><xsl:value-of select="title"/></td> <xsl:choose> <xsl:when test="price > 150"> <td bgcolor="#ff00ff"> <xsl:value-of select="author"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="author"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> In the above program we display those entries of Author column with pink color WHEN book price is higher than 150.
No comments:
Post a Comment