XSLT <if> Element Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report XSLT <if> Element is used to check the condition of the content of XML. The test is used to check the condition if it satisfies the condition then inside if is executed. Syntax: <xsl:if test=EXPRESSION> // Some output if the expression is true </xsl:if>Parameters: test: It is the condition that will check on the content of XML.Example 1: In this example, we will use the <xsl:if> tag to only show the CSE student in the table. Save Both files as mentioned and open xsl file on the Browser, it will show the output as shown below: XML <!--Test.xml--> <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl "href="Rule.xsl" ?> <student> <s> <name> Divyank Singh Sikarwar </name> <branch></branch> <age>18</age> <city> Agra </city> </s> <s> <name> Aniket Chauhan </name> <branch>CSE</branch> <age> 20</age> <city> Shahjahanpur </city> </s> <s> <name> Simran Agarwal</name> <branch>CSE</branch> <age> 23</age> <city> Buland Shar</city> </s> <s> <name> Abhay Chauhan</name> <branch>CSE</branch> <age> 17</age> <city> Shahjahanpur</city> </s> <s> <name> Himanshu Bhatia</name> <branch>IT</branch> <age> 25</age> <city> Indore</city> </s> </student> XML <!-- Rule.xsl--> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h1 align="center">Students' Basic Details</h1> <table border="3" align="center" > <tr> <th>Details</th> </tr> <xsl:for-each select="student/s"> <tr> <xsl:if test="branch='CSE'"> <td> <xsl:apply-templates select="name"/> <xsl:apply-templates select="branch"/> <xsl:apply-templates select="age"/> </td> </xsl:if> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> <xsl:template match="name"> Name: <span style="font-family:cursive;color:#ff0000"> <xsl:value-of select="."/> </span> <br /> </xsl:template> <xsl:template match="branch"> Branch: <span style="font-family:serif;color:#0ff000"> <xsl:value-of select="."/> </span> <br /> </xsl:template> <xsl:template match="age"> Age: <span style="font-family:fantsy;color:#0000ff"> <xsl:value-of select="."/> </span> </xsl:template> </xsl:stylesheet> Output: XSLT <if> Element Example 2: In this example, we will show the details of Student Dhananjay with the help of if tag. Save Both files as mentioned and open xsl file on the Browser, it will show the output as shown below: XML <!--Test.xml--> <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl "href="Rule.xsl" ?> <student> <s> <name>Dhananjay</name> <branch>CSE</branch> <age>18</age> </s> <s> <name> Aniket </name> <branch> CSE</branch> <age> 20</age> </s> <s> <name>Dhananjay</name> <branch> CE</branch> <age> 23</age> </s> <s> <name>Dhananjay</name> <branch>XE</branch> <age> 17</age> </s> <s> <name> Himanshu</name> <branch> IT</branch> <age>25</age> </s> <s> <name>Dhananjay</name> <branch>AI</branch> <age>25</age> </s> <s> <name>Max</name> <branch> IT</branch> <age>25</age> </s> <s> <name>Sam</name> <branch>ECE</branch> <age>25</age> </s> </student> XML <!--Rule.xsl--> <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <body> <h1 align="center">Students' Basic Details</h1> <table border="3" align="center" > <tr> <th>Name</th> <th>Branch</th> <th>Age</th> </tr> <xsl:for-each select="student/s"> <tr> <xsl:if test="name='Dhananjay'"> <td> <span style="color:#ff0000"> <xsl:value-of select="name"/></span> </td> <td> <span style="color:#0000ff"> <xsl:value-of select="branch"/></span> </td> <td> <span style="color:#00ff00"> <xsl:value-of select="age"/></span> </td> </xsl:if> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Output: XSLT <if> Element Comment More infoAdvertise with us Next Article XSLT Element S singhanuj78276 Follow Improve Article Tags : HTML Web technologies-HTML and XML Geeks Premier League 2023 Similar Reads XSLT <key> Element XSLT <key> Element is used to declare the key which is later used to identify the node with the help of the key function. The <xsl: key> tag assigns a specific key to an XML element And the key() function used to access this element of XML Syntax: <xsl:key name = "name" match = "patte 3 min read XSLT <sort> Element XSLT <sort> Element is used to sort the node which is selected. The XSLT <sort> element is added inside the <xsl:for-each> element. Syntax: <xsl:sort select= node order="ascending" | "descending" case-order="upper-first" | "lower-first" lang=XML:LANG-CODE data-type="text" | "num 3 min read XSLT <template> Element XSLT <template> element is a basic building block in XSLT and it provides a way to define rules for transforming specific elements into a source XML document. It is an instruction that tells a browser how to transform XML into something else. It looks for specific things in the XML called patt 2 min read XSLT <value-of> Element XSLT <value-of> Element is used to extract value from a node selected through name or expression. It is used to get value from XML and then display or output it. In this tutorial, we will learn to implement it. XSLT is a programming language used to convert XML documents into other forms such 2 min read XSLT <choose> Element The XSLT <choose> Element is used to define the choice among the values of the node. It is the same as the Switch keyword of the CPP language. Syntax: <xsl:choose> <xsl:when test="comparator"></xsl:when> <xsl:otherwise></xsl:otherwise> [It is case when test failes 3 min read XSLT <message> Element In XSLT (eXtensible Stylesheet Language Transformations), the '<xsl: message>' element outputs messages during the transformation process. It's a way to communicate information or provide feedback during the transformation. This element contains all the other XSL elements such as <xsl: text 1 min read Like