JSTL XML TAG:

In this part of the tutorial on JSTL, I explain the use of the XML tags of JSTL and show their wonderful simplicity, ease of use and raw power. The XML tag library is used to work with XML data used in JSP pages. The XML tag library helps parse and transform the data used in a JSP page. The XML tags can be used with the JSP pages after importing the following tag library by using the following code:

<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml"%>

XML tags are accessed by using the prefix 'x'. It is a predefined prefix used for XML tag libraries.

Types of XML Tags:

XML Core Tags:
The Core tags include the tags for parsing XML documents and performing X path operations. The XML Core tags are of three types:


XML Flow Control Tags:
The flow control tags help perform various operations such as easily parse and access XML data , iterate over elements in an XML document, and conditionally process JSP code fragments depending on the result of the given XPath expression.
The Xml Flow Control tags are of five types:

XML Transformation Tags: This tag provide support to transform the XML document with the given XSL stylesheet. This tag contain two tags:

Working With JSTL XML Tag: JSTL is mainly used for the web application, here i'll given a example in which i used JSTL Tags.

Create Table: First we create a table of Employee in which we take four fields EMPNO, DEPTNO, ENAME, SALORY. After this we create a DSN of name jstlxmltag.

Table:

table.gif

Create DSN:

dsn.gif

Create GetEmDetails.jsp Page:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<c:if test="${!empty param.language}" var="lang_flag">
<fmt:setLocale value="${param.language}"/>
</c:if>
<c:if test="${!empty param.country && lang_flag}">
<fmt:setLocale value="${param.language}_${param.country}"/>
</c:if>
<sql:setDataSource var="dataSource" driver="sun.jdbc.odbc.JdbcOdbcDriver" url="jdbc:odbc:jstlxmltag" scope="request"/>

<sql:query sql="select EMPNO,DEPTNO,ENAME, SAL from jstlxml" var="result" scope="page"
dataSource="${requestScope.dataSource}"/>
<html>
<body bgcolor="cyan">
Display Currency and Date in:<pre>
<a href="GetEmpDetails.jsp?language=en&country=US">English(US)</a>
<a href="GetEmpDetails.jsp?language=en&country=GB">English(UK)</a>
<a href="GetEmpDetails.jsp?language=en&country=AU">English(AU)</a>
</pre>
<table border="2">
<tr>
<c:forEach items="${pageScope.result.columnNames}" var="colname">
<th><c:out value="${colname}"/></th>
</c:forEach>
<th> </th>
</tr>
<c:forEach items="${pageScope.result.rows}" var="rows">
<tr><td>

<c:out value="${rows.EMPNO}"/>
</td><td>
<c:out value="${rows.DEPTNO}"/>
</td><td>
<c:out value="${rows.ENAME}"/>
</td><td>
<fmt:formatNumber value="${rows.SAL}" type="currency" />
</td></tr>
</c:forEach>
</table>

</body>
</html>

Build.xml File:

<?xml version="1.0" encoding="UTF-8"?>
<project name="JstlXmlTag" default="default" basedir=".">
<description>Builds, tests, and runs the project JstlXmlTag.</description>
<import file="nbproject/build-impl.xml"/>
</project>

Running the application:

Run the tomcat then write the below link in the URL
http://localhost:8081/jsp/

Here jsp is the Context path, which we mentioned in the server.xml file, which is present in (E:\Program Files\Apache Software Foundation\Tomcat 6.0\conf) directory.

OUTPUT:

ENGLISH (us):

eng_us.gif

English (uk):

enguk.gif

English (Au):

engau.gif

These are some another articles links related to this topic:

Starting with JSTL: http://www.c-sharpcorner.com/UploadFile/0d4935/started-with-jsp-standard-tag-library/