Easy Tutorial
❮ Jsp Exception Handling Jstl Function Substring ❯

<x:param> Tag

JSP Standard Tag Library

The <x:param> tag is used in conjunction with the <x:transform> tag to set parameters for an XSLT stylesheet.

Syntax

&lt;x:param name="<string>" value="<string>"/>

Attributes

The <x:param> tag has the following attributes:

Attribute Description Required Default Value
name The name of the XSLT parameter Yes Body
value The value of the XSLT parameter No None

Example Demonstration

The style.xsl file contains the following code, using the xsl:param tag with the {$bgColor} variable:

<?xml version="1.0"?>
&lt;xsl:stylesheet xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform" version="1.0">

&lt;xsl:output method="html" indent="yes"/>
&lt;xsl:param name="bgColor"/>

&lt;xsl:template match="/">
  <html>
  <body>
   <xsl:apply-templates/>
  </body>
  </html>
</xsl:template>

&lt;xsl:template match="books">
  <table border="1" width="50%" bgColor="{$bgColor}">
    &lt;xsl:for-each select="book">
      <tr>
        <td>
          <i><xsl:value-of select="name"/></i>
        </td>
        <td>
          &lt;xsl:value-of select="author"/>
        </td>
        <td>
          &lt;xsl:value-of select="price"/>
        </td>
      </tr>
    </xsl:for-each>
  </table>
</xsl:template>
</xsl:stylesheet>

The main.jsp file contains the following code, using the x:param tag within the x:transform tag:

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

<html>
<head>
  <title>JSTL x:param Tag</title>
</head>
<body>
<h3>Books Info:</h3>
&lt;c:set var="xmltext">
  <books>
    <book>
      <name>Padam History</name>
      <author>ZARA</author>
      <price>100</price>
    </book>
    <book>
      <name>Great Mistry</name>
      <author>NUHA</author>
      <price>2000</price>
    </book>
  </books>
</c:set>

&lt;c:import url="http://localhost:8080/style.xsl" var="xslt"/>
&lt;x:transform xml="${xmltext}" xslt="${xslt}">
   &lt;x:param name="bgColor" value="grey"/>
</x:transform>

</body>
</html>

The output is as follows:


JSP Standard Tag Library

❮ Jsp Exception Handling Jstl Function Substring ❯