David,
Thanks for your thoughts. I am going to digest what you suggest
further. I think another approach that is clean, albeit no Cocoon, is to
leave it as a servlet, and use xalan directly - something like:
// instantiate a TransformerFactory
javax.xml.transform.TransformerFactory tFactory =
javax.xml.transform.TransformerFactory.newInstance();
// ?? somehow attach a StringBuffer to the source instead of a file
javax.xml.transform.Source xmlSource =
new javax.xml.transform.stream.StreamSource
(new
java.net.URL("file:foo.xml").openStream());
// write all the XML to a/the StringBuffe here ........
// set the style sheet source
javax.xml.transform.Source xslSource =
new javax.xml.transform.stream.StreamSource
(new
java.net.URL("file:foo.xsl").openStream());
// Generate (instantiate) the transformer.
javax.xml.transform.Transformer transformer =
tFactory.newTransformer(xslSource);
// Perform the transformation, sending the output to the response.
transformer.transform(xmlSource,
new
javax.xml.transform.stream.StreamResult(out));
Bob Garvey
----- Original Message -----
From: "David Rosenstrauch" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, January 23, 2002 11:44 AM
Subject: Re: Servlet to XSL possible?
> OK. I think I get it now.
>
> Yes, Tomcat will always handle the servlets, and since your servlet is not
a Cocoon generator things won't work properly. Servlets are designed to
write directly to the http response stream (which is what you are seeing).
>
> Cocoon on the other hand is designed for you to process xml elements via
pipeline transformations and (eventually) serialize the output to the http
response stream.
>
> So ... how to do what you want?
>
> Some ideas:
>
> 1) Kludgey:
>
> Make your servlet act as a Cocoon generator as well. Have it implement
the appropriate interface and generate the appropriate XML when called.
>
> 2) less kludgey:
>
> Avoid calling a servlet completely.
>
> Refactor your servlet into 2 pieces: one that does the actual servlet
call/response stuff ("doGet", etc.) and a separate component of stand-alone
code that really does the meat of what you're trying to do (generate XML it
sounds like).
>
> (Or alternatively, just add a new method to the servlet that you can call
to retrieve the XML without going through all the HTTP stuff.)
>
> Then use a custom written Generator (or maybe even an Action or XSP) to
call the new component directly and feed the results into the pipeline.
>
>
> Haven't thought this all through too carefully so maybe this is tougher
than it sounds, but in theory I would think this should work.
>
> Any help?
>
>
> DR
>
>
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>