Use of <x:transform> tag of JSTL

In this section we will learn how to use <x:parse>
tag of Xml tag library of Jstl. This tag is used to transform the specified
xml document. With the use of this tag we can display data from xml document in
a format that is already defined in .xslt file.
Standard Syntax : <%@ taglib prefix="x"
uri="http://java.sun.com/jsp/jstl/xml" %>
| Attributes: |
|
var |
Name of the variable
used to store parsed xml content. |
|
result |
Result object that
capture the result after transformation. |
|
scope |
Defines scope of the
defined variable in var attribute. |
|
xml |
This is deprecated
attribute, now we are using 'doc' attribute. |
| xmlSystemId |
This is deprecated
attribute, used with attribute 'xml'. |
| doc |
Source xml document
to be transformed. |
| docSystemId |
URI of the xml
document. |
| xslt |
javax.xml.transform.Source
Transformation stylesheet. |
| xsltSystemId |
URI of the xslt
document. |
transform_xmlJstlTag.jsp
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
<c:import var="xml" url="employee.xml" />
<c:import var="xsl" url="employee.xsl" />
<x:transform xml="${xml}" xslt="${xsl}" />
|
employee.xml
<?xml version="1.0" encoding="UTF-8"?>
<org>
<company>
<emp>
<name>Ravi Kant</name>
<designation>Sr. Sofware developer</designation>
<age>28</age>
</emp>
<emp>
<name>Suman Saurabh</name>
<designation>Sr Graphics Designer</designation>
<age>27</age>
</emp>
</company>
<company>
<emp>
<name>Vinod Kumar</name>
<designation>Sr. Java Programmer</designation>
<age>27</age>
</emp>
<emp>
<name>Mr. Santosh</name>
<designation>Sr. Flash Programmer</designation>
<age>25</age>
</emp></company>
</org>
|
employee.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="doc"/>
<xsl:template match="/">
<html>
<body>
<h2>Company's Employee detail</h2>
<table border="1">
<tr>
<th align="left">name
</th>
<th align="left">designation
</th>
<th align="left">age
</th>
</tr>
<xsl:for-each select="org/company/emp">
<tr>
<td>
<xsl:value-of select="name"/>
</td>
<td>
<xsl:value-of select="designation"/>
</td>
<td>
<xsl:value-of select="age"/>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
|
Output :

Download Source Code

|