?
Solved

Passing parameters to XSL using JSTL?

Posted on 2008-10-22
3
Medium Priority
?
1,465 Views
Last Modified: 2013-11-24
I'm trying to pass a couple parameters back to XSL using the JSTL tag library, but the values are not getting passed.  My code is attached.  

The page loads, but the two values are not being passed.  All I get is a page without any content that would have been filled in the for-each loop.


///// JSP code ////
 
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="x" uri="http://java.sun.com/jstl/xml" %>
<%
	String pageStart = "1";
	String pageLimit = "10";
	
	if (request.getParameter("s") != null)
	{
		pageStart = (String)request.getParameter("s");
	}
	
	if (request.getParameter("l") != null)
		pageLimit = (String)request.getParameter("l");
	
	pageContext.setAttribute("pageStart",pageStart);
	pageContext.setAttribute("pageLimit",pageLimit);
 
%>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>
 
<body>
    <c:import url="test2.xml" var="xmldoc" />
    <c:import url="test2.xsl" var="xslt" />
    <x:transform xml="${xmldoc}" xslt="${xslt}">
    	<x:param name="pageLimit" value="1"/>
         <x:param name="pageStart" value="10"/>
    </x:transform>
</body>
</html>
 
 
 
////// XSL: /////////
<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
	<xsl:template match="/">
      <xsl:param name="pageStart" />
      <xsl:param name="pageLimit" />
      <xsl:variable name="end" select="$pageStart + $pageLimit - 1"/>
  	  <xsl:variable name="docsort" select="Table/Row[position() &gt;= $pageStart and position() &lt;= $end]"/>
      <html>
        <body>
          <h2>Testing</h2>
          <table>
            <tr>
              <td>
                <xsl:if test="$pageStart - $pageLimit &gt;= 1">
                    <a href="?s={$pageStart - $pageLimit}&amp;l={$pageLimit}">prev</a>
                </xsl:if>
              </td>
              <td align="right">
                <a href="?s={$pageStart + 1}&amp;l={$pageLimit}">next</a>
              </td>
            </tr>
            <tr bgcolor="#CCCCCC">
              <th>Element 1</th>
              <th>Element 2</th>
            </tr>
            <xsl:for-each select="$docsort">
                    <tr>
                    	<xsl:for-each select="Table/Row/Cell">
                      		<td><xsl:value-of select="element1"/></td>
                      	</xsl:for-each>
                    </tr>
            </xsl:for-each>
          </table>
        </body>
      </html>
	</xsl:template>
</xsl:stylesheet>
 
//// XML FILE ////
 
<?xml version="1.0"?>
<Table>
   <Row>
    <Cell>testing</Cell>
    <Cell>John/Cell>
    <Cell>Smith</Cell>
    <Cell>Ohio</Cell>
   </Row>
</Table>

Open in new window

0
Comment
Question by:cacklebunny
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 400 total points
ID: 22777024
The parameters are local to the template for match="/"
and should be global

 <?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
      <xsl:param name="pageStart" />
      <xsl:param name="pageLimit" />
      <xsl:template match="/">
...

should work
 
0
 
LVL 2

Author Closing Comment

by:cacklebunny
ID: 31508760
Sure did, thanks!
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 22781246
welcome
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question