JSTL XML x:param Tag

The tag is subtag of <x:transform> tag. This tag is used with transform tag to set a parameter in the XSLT stylesheet. This tag is used as nested with <x:transform> tag for sending the parameter along with the values.

Syntax of xml <x:param> tag

<x:param name=”string” value=”string”></x:param>

Attributes of xml <x:param> tag

  • name : This attribute specifies the name of the XSLT parameter
  • value : This attribute specifies the value of the XSLT parameter.

Example of xml x:param tag

<em><strong>Listing 1:XML file-param.xml</strong></em>
<?xml version="1.0" ?>
		<roll>Software Designer</roll>
		<roll>Web Designer</roll>
		<roll>Java Programmer</roll>
<span style="font-size: 12px; line-height: 18px;">	</employee></span>
<span style="font-size: 12px; line-height: 18px;"></employee></span>

Listing 2:XSL File-param.xsl

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />
	<xsl:param name="color" />
	<xsl:param name="color1" />
	<xsl:param name="color2" />
	<xsl:template match="employee">
				<h2>Employee Detail</h2>
				<table border="1">
						<td align="left">
						<td align="left">
						<td align="left">
<span style="font-size: 12px; line-height: 18px;">					<xsl:for-each select="employee"></span>
<span style="font-size: 12px; line-height: 18px;">						<tr></span>
<span style="font-size: 12px; line-height: 18px;">							<td bgColor="{$color}"></span>
<span style="font-size: 12px; line-height: 18px;">								<i></span>
									<xsl:value-of select="name" />
<span style="font-size: 12px; line-height: 18px;">							</td></span>
							<td bgColor="{$color1}">
								<xsl:value-of select="roll" />
							<td bgColor="{$color2}">
								<xsl:value-of select="designation" />
<span style="font-size: 12px; line-height: 18px;">						</tr></span>
<span style="font-size: 12px; line-height: 18px;">					</xsl:for-each></span>
<span style="font-size: 12px; line-height: 18px;">				</table></span>
<span style="font-size: 12px; line-height: 18px;">			</body></span>
<span style="font-size: 12px; line-height: 18px;">		</html></span>
<span style="font-size: 12px; line-height: 18px;">	</xsl:template></span>
<span style="font-size: 12px; line-height: 18px;"></xsl:stylesheet></span>

Details of the Code

  • We have written the above file in xsl sheet and named as transform.xsl
  • <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/> tag is used define the format of the output document.
  • <xsl:param name="color"/> tag is used to display parameter name
  • <xsl:template match="employee"> tag is used to match the specified node in the document.
  • <xsl:for-each select="employee"> 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 3:JSP file-example.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"


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

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

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


<%@ page language="java" contentType="text/html; charset=UTF-8"
<%@ taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">


<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">

<title>JSTL x:param Example</title>

	<c:import url="param.xml" var="xmlDoc" />
	<c:import url="param.xsl" var="xslDoc" />
	<x:transform doc="${xmlDoc}" xslt="${xslDoc}">
		<x:param name="color" value="yellow" />
		<x:param name="color1" value="red" />
		<x:param name="color2" value="pink" />
<span style="font-size: 12px; line-height: 18px;"></body></span>
<span style="font-size: 12px; line-height: 18px;"></html></span>

Details of the Code

  • <c:import url="param.xml" var="xmlDoc" />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
  • <x:transform doc="${xmlDoc}" xslt="${xslDoc}"> tag is used to transform the xml file into other format
  • <x:param name="color" value="yellow"/> tag is used to set the transformation parameter.

Steps for Execution

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

  • Save this file as example.jsp in your eclipse IDE.
  • Now select this jsp file, right mouse click and select Run as ->Run on server


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

Previous Tutorial :  JSTL XML x:choose ,x:when and x:otherwise Tags :: Next Tutorial : JSTL SQL Tags Library

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!