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

How to write a stream-oriented XSLT filter?

Subject: How to write a stream-oriented XSLT filter?
From: John English <john.foreign@xxxxxxxxx>
Date: Tue, 26 Mar 2013 16:41:30 +0200
 How to write a stream-oriented XSLT filter?
Apologies in advance: this is not an XSLT-specific question, but I thought someone here might be able to help me anyway...

I have an XSLT filter which transforms XML output from a servlet to HTML. The filter uses a CharResponseWrapper to extract the response output as a string and then run it through the transformer:

      CharResponseWrapper wrapper =
          new CharResponseWrapper((HttpServletResponse)response);
      chain.doFilter(request,wrapper);
      s = wrapper.toString();
      if (s.length() > 0) {
        Transformer transformer = xslt.newTransformer();
        Source transformSource = new StreamSource(new StringReader(s));
        StreamResult result = new StreamResult(response.getWriter());
        transformer.transform(transformSource, result);
      }

This works fine unless the output is larger than a certain size, at which point I get an OutOfMemoryError.

The sensible way to deal with this would presumably be to connect up the response's output stream to the transformer's input source, so that I don't have to materialise all the output as a string before I start transforming it. I can't find any examples which show how I can do this; all the examples I've seen also work by materialising the output as a string before processing it.

It seems like I will need to move the transformation into the response wrapper, and maybe a separate thread to run the transformation while the response is being generated, but it all seems incredibly complicated. I'm hoping it's not as complicated as I imagine, and that someone here has already gone through all this and will be able to tell me how to proceed.

Please can anyone point me in the right direction here?

TIA,
--
John English

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.