GeeCON Prague 2014*
The moose likes JSP and the fly likes JSP with XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JSP with XSL" Watch "JSP with XSL" New topic
Author

JSP with XSL

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
Hi,
Can anyone please tell me how to transform an XML file using an XSL file in JSP page?
Thanks.
Shawn Bayern
Author
Ranch Hand

Joined: May 06, 2002
Posts: 160
Originally posted by amit sanghai:
Hi,
Can anyone please tell me how to transform an XML file using an XSL file in JSP page?
Thanks.

The JSP Standard Tag Library (JSTL) introduces a standard tag, <x:transform>, for calling XSLT from a JSP page. You can read more about JSTL at
http://java.sun.com/products/jsp/jstl
and download an implementation from
http://jakarta.apache.org/taglibs/doc/standard-doc/intro.html


Shawn Bayern<br />"JSTL in Action" <a href="http://www.jstlbook.com" target="_blank" rel="nofollow">http://www.jstlbook.com</a>
George Joseph
Greenhorn

Joined: Nov 05, 2001
Posts: 24
Hi Amit,
To transform an XML file using an XSL file in JSP page, you can use the xalan package from Apache.
Suppose u have a xml file content.xml and corresponding style file style.xml, then the required code will be
---------------------- xalanxsl.jsp -------------

<%@ import="java.io.*,org.apache.xalan.xslt.*,org.apache.xalan.xpath.*"%>
<%
ByteArrayOutputStream bStream=new ByteArrayOutputStream();
XSLTProcessor processor ;
try
{
processor= XSLTProcessorFactory.getProcessor();
XSLTInputSource inputxml=new XSLTInputSource("content.xml");
XSLTInputSource inputxsl=new XSLTInputSource("style.xsl");
processor.process(inputxml,inputxsl,new XSLTResultTarget(bStream));
}
catch(Exception e)
{
System.err.println(e.getMessage());
}
%>
<!--Displaying the HTML OUTPUT by combing XML and XSL -->
<%=bStream%>
<!--End-->

---------------------- xalanxsl.jsp -------------
Remember you need to set xalan.jar in the class path.

George Joseph,
Transversal E Networks.
[ June 29, 2002: Message edited by: George Joseph ]
 
GeeCON Prague 2014
 
subject: JSP with XSL