[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

xslt servlet that uses foo.xml and rewrites foo.xml

Subject: xslt servlet that uses foo.xml and rewrites foo.xml
From: "Robert Koberg" <rob@xxxxxxxxxx>
Date: Sun, 29 Apr 2001 07:44:19 -0700
xslt servlet
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.