Two Laptop Bag*
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
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with XSL Tranformation in Servlet
 
Similar Threads
Error while using TransformerHandler
How to stream xml document to inputSource?
How to pass output of SAX Transformation to XSLTransformation
Xalan XSLT Sax Parsing
TransformerHandler not passing through comments