File: jspSample.jsp

package info (click to toggle)
libxalan2-java 2.7.1-5
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 19,468 kB
  • ctags: 26,006
  • sloc: java: 175,784; xml: 28,073; sh: 164; jsp: 43; makefile: 43; sql: 6
file content (48 lines) | stat: -rw-r--r-- 1,545 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<%@ page language="java" contentType="text/html" %>
<%@ page import="javax.xml.transform.*"%>
<%@ page import="javax.xml.transform.stream.*"%>
<html>
<head>
<title>JSP sample passing a parameter to XSL</title>
</head>
<body>
<%! String FS = System.getProperty("file.separator"); %>
<%
/**
 * This JSP uses PMA to set param1 in the
*  foo.xsl stylesheet before using the
 * stylesheet to transform foo.xml
 * and outputing the result.
 *
 * Invoke the jsp from the appropriate
 * context for your servlet/jsp server.
 * For example: http://localhost:8080/samples/jspSample.jsp?PMA=HellowWorld!&XML=foo.xml&XSL=foo.xsl
 * This example assumes that foo.xsl and foo.xml
 * are in the same directory. 
 * Output should be Hello (from foo.xsml) and HelloWorld!
 * (value of param1 in foo.xsl).

 *@author Paul Campbell seapwc@halcyon.com
 *@version $Id: jspSample.jsp 337275 2003-02-20 18:43:14Z ilene $
 */
 

String paramValue = request.getParameter("PMA");
String xmlFile    = request.getParameter("XML");
String xslFile    = request.getParameter("XSL");

// get the real path for xml and xsl files;
	String ctx = getServletContext().getRealPath("") + FS;
	xslFile = ctx + xslFile;
	xmlFile = ctx + xmlFile;

TransformerFactory tFactory = 
	TransformerFactory.newInstance();
Transformer transformer =
	tFactory.newTransformer(new StreamSource(xslFile));
	transformer.setParameter("param1", paramValue);
	transformer.transform(
		 new StreamSource(xmlFile), new StreamResult(out));
%>
</body>
</html>