aspose file tools*
The moose likes Servlets and the fly likes Problem with XSL Tranformation in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with XSL Tranformation in Servlet" Watch "Problem with XSL Tranformation in Servlet" New topic

Problem with XSL Tranformation in Servlet

Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86

I need to generate some HTML from an XSL Tranformation. XML is generated on the fly. The XSL File is static. My code looks like this.

PrintWriter out = response.getWriter();
StreamResult streamResult = new StreamResult(out);

SAXTransformerFactory saxTransformerFactory = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
File xsltFile = new File(getServletContext().getRealPath("/xml/html.xsl"));
Source xsltSrc = new StreamSource(xsltFile);
Templates templates = saxTransformerFactory.newTemplates(xsltSrc);
TransformerHandler handler = saxTransformerFactory.newTransformerHandler(templates);

// custom xml generator nothing special
// just: handler.startElement ...
XmlTransformer xmlt = new XmlTransformer();

SAXResult result = new SAXResult(handler);

I only get null as error message. I can't figure out what's wrong. XML Generator works ok for normal xml output. Can anyone help?

Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
I just did some addional debugging and discovered that the java runtime exception occurs when the handler.endDocument() method is called. Does anyone know what this means?
Don't get me started about those stupid light bulbs.
subject: Problem with XSL Tranformation in Servlet
Similar Threads
How to pass output of SAX Transformation to XSLTransformation
How to stream xml document to inputSource?
TransformerHandler not passing through comments
Xalan XSLT Sax Parsing
Error while using TransformerHandler