Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP with XSL

 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
George Joseph
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic