Subject: [xsl] xslt servlet that uses foo.xml and rewrites foo.xml From: "Robert Koberg" <rob@xxxxxxxxxx> Date: Sun, 29 Apr 2001 07:44:19 -0700 |
Hi, I am trying to write a servlet that takes an XML file transforms that file and rewrites it. When I try the code below I get a malformed document exception (no root element) because the document (Result I assume) is prepared for writing??? by having everything deleted form it. How can I write a simple servlet that rewrites the source document? How can I get the the StreamSource into a variable so I can transform it back into the original file? Note: if I write out to a new file there is no problem with the transformation. ----------------------------------- public class AddPage extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { res.setContentType("text/plain"); PrintWriter out = res.getWriter(); String xmlref = "c:/resin/doc/ed/xml/config.xml"; String xslref = "c:/resin/doc/ed/xml/addpage.xsl"; String parentElem = req.getParameter("parentElem"); try { TransformerFactory tFactory = TransformerFactory.newInstance(); Transformer transformer = tFactory.newTransformer(new StreamSource(xslref)); transformer.setParameter("id",parentElem); StreamSource strmsrc = new StreamSource(xmlref); //StreamResult strmrslt = new StreamResult(xmlref); transformer.transform (strmsrc, new StreamResult(xmlref)); } catch (Exception e) { out.write(e.getMessage()); e.printStackTrace(out); } out.close(); } --------------------------- Thanks, Rob XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] matching input value to a, Dan Diebolt | Thread | [xsl] test for a empty node, tanz |
Re: [xsl] html output, Jeni Tennison | Date | [xsl] test for a empty node, tanz |
Month |