How to use<xsl:if> element in XSLT?
Answer:
Using <xsl:if> element we can test the content of an XSL document. Syntax: <xsl:if test="expression"> ...Write here output it will dispay when condition is true... </xsl:if> I have given you example to use of <xsl:if> element. <?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"> <xsl:if test="price > 150"> <tr> <td><xsl:value-of select="title"/></td> <td><xsl:value-of select="author"/></td> </tr> </xsl:if> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> It will give the title of book with related author which book cost greater than 150.
No comments:
Post a Comment