This tag is to use to define the Control statements In JSP. Like to choose or select from conditional Criteria…!
“Voter.xml” (XML File for Program)
<?xml version=”1.0″ ?>
<voter>
<vote>
<name>Dev</name>
<age>18</age>
</vote>
<vote>
<name>Ashu</name>
<age>20</age>
</vote>
</voter>
If.jsp
<%@ taglib uri=”http://java.sun.com/jsp/jstl/core” prefix=”c” %>
<%@ taglib uri=”http://java.sun.com/jsp/jstl/xml” prefix=”x” %>
<html>
<head>
<title><x:if>Tag In JSTL</title>
</head>
<body>
<center><b><h3>Voting Eligibility</h3>
<c:import url=”voter.xml” var=”vtr”/>
<x:parse xml=”${vtr}” var=”disp”/>
<x:if select=”$disp//vote”>
<p><center><b>Only One Can vote </b></center></p>
</x:if> <br />
<x:if select=”$disp/voter[1]/vote/age <= 18″>
<center><b><p>You can Vote…</p></b></center>
</x:if>
</body>
</html>
In This Program We Create a XML File as per Mention above named ‘Voter.xml’. That will be accessed while compiling the Program. Required attributes are also declared with the mandatory Variable. The Body section contains the main part of structure like Import URL will import the contents from XML file on The Web page. The Condition will be checked as per either the candidate will vote or not. In the Last all the tags will be closed.