• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

JSP with XSL

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic