cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Upayavira ...@odoko.co.uk>
Subject Re: XSLT transformation
Date Fri, 05 Aug 2005 10:22:20 GMT
Antony Grinyer wrote:
> Thanks to everyone's help I believe I'm getting closer to getting this
> working...darn...I didn't realize transforming XML in Cocoon could cause
> such a problem!

Presumably that is working with XML in Java can cause such a problem. As 
soon as you break out of Cocoon into Java, you're much more on your own.

 > I've now changed my code to:
> 
>  private void generateDocumentToSAX(String queryResults)
>   {
>     try
>     {
>       XMLReader parser = XMLReaderFactory.createXMLReader();
>       parser.setContentHandler(this);
>       InputSource inputSource = new InputSource(new
> StringReader(queryResults));
>       parser.parse(inputSource);
>     }
>     catch(Exception e)
>     {
>       m_resultMessage = "Unable to get parser: " + e.toString();
>       this.getLogger().error(m_resultMessage);
>     }
>   }
> 
> And I get this error in the sitemap.log:
> 
> ----
> Unable to get parser: java.lang.UnsupportedOperationException: The
> TransformerHandler is not serially reusable. The startDocument() method
> must be called once only.
> -----
> 
> I think this might be happening because I pass in XML to the java class
> transformer (containing the above method) which finds/creates the
> startDocument element in the startElement method, and then the parser in
> the method above creates another startDocument element, which is
> confusing the saxon xslt transformer? I'm confused here now - if the
> purpose of a Cocoon transformer is to take in some XML, change it, then
> spit out the changed XML, why are the xlst (saxon, xalan) transformers
> complaining about duplicated startDocument elements? Sure you can use a
> parser to create Sax events within a transformer java class which
> extends the AbstractSAXTransformer class?

I know I suggested using XMLReader, but given Conal's comment, why not 
just try SAXParser with Conal's fix? Basically, parsing a document you 
start with emitting a startDocument event. However, the startDocument 
event must already have been called - you've already emitted 
startElement events.

If you still need to get rid of startDocument/endDocument events, you 
need to create a NullDocEventPipe, which consumes them but does not emit 
them. You give that to your parser as the content handler, and give the 
content handler Cocoon gave you to your NullDocEventPipe. Make sense? 
This is pretty easy to do, I might even have one I can let you have.

Regards, Upayavira




---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message