This tag used to create a loop over xml Documents this shows the value In which this is been implemented.
Worker.xml
<?xml version=”1.0″ ?>
<workers>
<wrkr>
<name>Raj</name>
<age>23</age>
<dob>12-07-1992</dob>
</wrkr>
<wrkr>
<name>Suresh</name>
<age>30</age>
<dob>13-03-1984</dob>
</wrkr>
<wrkr>
<name>Mohit</name>
<age>20</age>
<dob>10-05-1994</dob>
</wrkr>
<wrkr>
<name>Ram</name>
<age>35</age>
<dob>1-03-1979</dob>
</wrkr>
</workers>
……
forEach.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:forEach>Tags In JSTL</title>
</head>
<body>
<center><b><h3>Worker Info:</h3></b></center>
<c:import url=”workers.xml” var=”lbr”/>
<x:parse xml=”${lbr}” var=”disp”/>
<ul class=”list”>
<x:forEach select=”$disp/workers/wrkr/name” var=”prd”>
<center><b><li>Name Of Workers :<x:out select=”$prd” /></li></b></center>
</x:forEach>
</ul>
</body>
</html>
This program defines the working procedure of forEach tag. This tag is used to create a loop over XML doc. This will shows the result according to implemented condition. The main attribute of this tag is var ‘variable name’ that will use to access the tag and will store the fetched value on web browser. Xml file reference also been used as mention above. All the tags must be closed at last.