This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one 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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Problem with XSL Tranformation in Servlet" Watch "Problem with XSL Tranformation in Servlet" New topic
Author

Problem with XSL Tranformation in Servlet

Pete Neu
Ranch Hand

Joined: Feb 18, 2005
Posts: 86
Hello,

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();
xmlt.generateXML(handler,gr,av,dataList);

SAXResult result = new SAXResult(handler);
handler.setResult(result);

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?

cheers,
Pete
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?
 
jQuery in Action, 2nd edition
 
subject: Problem with XSL Tranformation in Servlet