JSTL XML x:transform Tag

The <x:transform> tag is used to transform an xml data based on XSLT script. This tag used to apply an XSL transformation on an XML document.

Syntax of <x:transform> Tag

<x:transform attributes> body content </x:transform>

Attributes of <x:transform> Tag

varThis attribute specifies the variable name to which transformed XML document has to be set.
scopeThis attribute specifies the scope of the var attribute.
docThis attribute specifies the source XML document to be transformed.
xsltThis attribute specifies javax.xml transform source transform stylesheet as string, reader or source object.
xmlSystemIdThis attribute is deprecated attribute, used with attribute xml.
docSystemIdThis attribute takes the system identifier(URI) for parsing the XML document.
resultThe javax.xml transform. result object that captures or processes the transformation result.

Example of <x:transform> Tag

Listing 1:transform.xsl file

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="doc"/>

<xsl:template match="/">

<h2>Company's Employee detail</h2>

<table border="1">
<th align="left">name
<th align="left">designation
<th align="left">age
<xsl:for-each select="org/company/emp">
<xsl:value-of select="name"/>
<xsl:value-of select="designation"/>
<xsl:value-of select="age"/>


Details of the Code

  • We have written the above file in xsl sheet and named as transform.xsl
  • <xsl:param name=”doc”/> tag is used to display parameter name.
  • <xsl:template match=”/”> tag is used to match the specified node in the document.
  • <xsl:for-each select=”org/company/emp”> tag is used to loop the nodes in the xml document.
  • <xsl:value-of select=”name”/> tag is used to select the particular value in the document.

Listing 2:Xml File transfor.xml

<?xml version="1.0" encoding="UTF-8"?>
<name>Mahantesh Nagathan</name>
<designation>Sr. Sofware developer</designation>

<name>Rushali Bhatkande</name>
<designation>Graphics Designer</designation>

<name>Ganesh Patil</name>
<designation>Sr. Java Programmer</designation>

<name>Maruti Patil</name>
<designation>Sr. Flash Programmer</designation>

Listing 3:JSP file-example.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="transform.xml" />
<c:import var="xsl" url="transform.xsl" />
<x:transform xml="${xml}" xslt="${xsl}" />

Details of the Code

  • <c:import var=”xml” url=”transform.xml” /> tag is used to include the content of another resource in the current JSP. The var attribute is used to specify the variable name to which transformed XML document has to be set. The url is transform.xml
  • <c:import var=”xsl” url=”transform.xsl” /> in this tag the url is transform.xsl
  • <x:transform xml=”${xml}” xslt=”${xsl}” /> tag is used to transform the xml file into other format.

Steps for Execution

Before executing the xml programs we should add jar files namely:

  • Click on the jsp File
  • Right click on mouse and select run as ->click run on server
  • Then output page will get displayed.


When the execution process is completed successfully we will get the following output :
JSTL xml x transform tag


Previous Tutorial :  JSTL XML x:parse Tag :: Next Tutorial : JSTL XML x:choose ,x:when and x:otherwise Tags

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!