This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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

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?
Have you checked out Aspose?
subject: Problem with XSL Tranformation in Servlet
It's not a secret anymore!