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" ?> <employee> <employee> <name>Mahantesh</name> <roll>Software Designer</roll> <designation>Associate</designation> </employee> <employee> <name>Rushali</name> <roll>Web Designer</roll> <designation>Associate</designation> </employee> <employee> <name>Ganesh</name> <roll>Java Programmer</roll> <designation>Associate</designation> <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" version="1.0"> <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"> <html> <body> <h2>Employee Detail</h2> <table border="1"> <tr> <td align="left"> <b>Name</b> </td> <td align="left"> <b>designation</b> </td> <td align="left"> <b>Age</b> </td> </tr> <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" /> </i> <span style="font-size: 12px; line-height: 18px;"> </td></span> <td bgColor="{$color1}"> <xsl:value-of select="roll" /> </td> <td bgColor="{$color2}"> <xsl:value-of select="designation" /> </td> <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" pageEncoding="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" "http://www.w3.org/TR/html4/loose.dtd"> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="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"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>JSTL x:param Example</title> </head> <body> <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" /> </x:transform> <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:
xalan-2.7.0.jar
- 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
Output
When the execution process is completed successfully we will get the following output :
Previous Tutorial : JSTL XML x:choose ,x:when and x:otherwise Tags :: Next Tutorial : JSTL SQL Tags Library