Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] TransformerHandler Chaining with Java and Saxon

From: "Scott Lynch" <slynch@------.--->
To: <xsl-list@-----.------------.--->
Date: 6/3/2009 2:08:00 PM
Upgrading to 9.1 solved the problem. Sorry for the list noise!

cheers,
Scott 

-----Original Message-----
From: Lynch, Scott (GWRTP:8792) 
Sent: Wednesday, June 03, 2009 9:57 AM
To: xsl-list@l...
Subject: RE: [xsl] TransformerHandler Chaining with Java and Saxon

Thanks, Michael. I'll try upgrading to see if things get better.

cheers,
Scott 

-----Original Message-----
From: Michael Kay [mailto:mike@s...]
Sent: Tuesday, June 02, 2009 7:14 PM
To: xsl-list@l...
Subject: RE: [xsl] TransformerHandler Chaining with Java and Saxon

Could be this bug

https://sourceforge.net/tracker/index.php?func=detail&aid=1558231&group_
id=2
9872&atid=397617

though that's documented as applying to 8.8 rather than 8.9.

Another candidate is this one, in 9.0

https://sourceforge.net/tracker/?func=detail&aid=1986836&group_id=29872&
atid
=397617

I suggest you try it on a more recent release. The current release is
9.1.0.6.

Also, I suggest you raise Saxon-specific problems on the saxon-help list
at SourceForge.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay  

> -----Original Message-----
> From: Scott Lynch [mailto:slynch@n...]
> Sent: 02 June 2009 23:50
> To: xsl-list@l...
> Subject: [xsl] TransformerHandler Chaining with Java and Saxon
> 
> All,
> 
> This is not quite an xsl question, but hopefully someone here has seen

> this before and can help me, because I've been banging my head on my 
> keyboard for hours now. I'm trying to chain together several 
> transforms using the TransformerHandler chaining design pattern in 
> Java with the Saxon (8.9) engine. The code below invariable throws an 
> exception complaining about "The TransformerHandler is not serially 
> reusable. The
> startDocument() method must be called once only." when the
> reader.parse(source) method is invoked. 
> 
> Does anyone know why this would be happening and how to prevent it? I 
> am able to individually transform my file with the transforms by using

> a set of rotating temporary files, but I would like to increase the 
> speed of the transformation (I'm transforming about 17 files 
> comprising 50meg of data through about 10 transforms and this is 
> taking several
> minutes) using chaining if possible.
> 
> thanks,
> Scott
> 
> 
>     private String multiTransform(String sourceFileName, List<String> 
> transformFiles, String startKey)
>     {
>         String outFileName = "transformOutput.xml";
>         try
>         {
>             TransformerFactory factory = 
> TransformerFactory.newInstance();
>             SAXTransformerFactory saxTFactory =
> ((SAXTransformerFactory) factory);
>             List<TransformerHandler> handlers = new 
> ArrayList<TransformerHandler>();
>             TransformerHandler previousHandler = null;
>             for (String transformFile : transformFiles)
>             {
>                 StreamSource source = new 
> StreamSource(Resources.getResource(transformFile).openStream());
>                 TransformerHandler handler = 
> saxTFactory.newTransformerHandler(source);
>                 handlers.add(handler);
>                 if (previousHandler != null)
>                 {
>                     previousHandler.setResult(new SAXResult(handler));
>                     break;
>                 }
>                 previousHandler = handler;
>             }
> 
>             XMLReader reader = XMLReaderFactory.createXMLReader();
>             reader.setContentHandler(handlers.get(0));
> 
>             TransformerHandler lastHandler =
> handlers.get(handlers.size() - 1);
>             OutputStream resultOutStream = new 
> FileOutputStream(outFileName);
>             StreamResult xformOutResult = new 
> StreamResult(resultOutStream);
>             lastHandler.setResult(xformOutResult);
>             FileInputStream fileInStrm = new 
> FileInputStream(sourceFileName);
>             InputSource source = new InputSource(fileInStrm);
>             reader.parse(source);
>         }
>         catch (Exception e)
>         {
>             e.printStackTrace();
>         }
>         return outFileName;
>     }
> 
> 
> 
> The exception...
> 
> java.lang.UnsupportedOperationException: The TransformerHandler is not

> serially reusable. The
> startDocument() method must be called once only.
> 	at
> net.sf.saxon.TransformerHandlerImpl.startDocument(TransformerH
> andlerImpl
> .java:69)
> 	at
> net.sf.saxon.event.ContentHandlerProxy.open(ContentHandlerProx
> y.java:242
> )
> 	at net.sf.saxon.event.ProxyReceiver.open(ProxyReceiver.java:76)
> 	at
> net.sf.saxon.event.ImplicitResultChecker.open(ImplicitResultCh
> ecker.java
> :24)
> 	at
> net.sf.saxon.event.ImplicitResultChecker.firstContent(Implicit
> ResultChec
> ker.java:59)
> 	at
> net.sf.saxon.event.ImplicitResultChecker.startElement(Implicit
> ResultChec
> ker.java:30)
> 	at
> net.sf.saxon.event.NamespaceReducer.startElement(NamespaceRedu
> cer.java:5
> 4)
> 	at
> net.sf.saxon.event.ComplexContentOutputter.startContent(Comple
> xContentOu
> tputter.java:481)
> 	at
> net.sf.saxon.event.ComplexContentOutputter.characters(ComplexC
> ontentOutp
> utter.java:136)
> 	at net.sf.saxon.instruct.Copy.processLeavingTail(Copy.java:164)
> 	at
> net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:338)
> 	at
> net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:99)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTempl
> ates.java:
> 319)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.apply(ApplyTemplates.java:189)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.process(ApplyTemplates.java:149)
> 	at
> net.sf.saxon.instruct.ElementCreator.processLeavingTail(Elemen
> tCreator.j
> ava:250)
> 	at net.sf.saxon.instruct.Copy.processLeavingTail(Copy.java:152)
> 	at
> net.sf.saxon.instruct.Choose.processLeavingTail(Choose.java:338)
> 	at
> net.sf.saxon.instruct.Template.applyLeavingTail(Template.java:99)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTempl
> ates.java:
> 319)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.defaultAction(ApplyTempla
> tes.java:3
> 51)
> 	at
> net.sf.saxon.instruct.ApplyTemplates.applyTemplates(ApplyTempl
> ates.java:
> 312)
> 	at
> net.sf.saxon.Controller.transformDocument(Controller.java:1602)
> 	at
> net.sf.saxon.TransformerHandlerImpl.endDocument(TransformerHan
> dlerImpl.j
> ava:133)
> 	at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.e
> ndDocument
> (AbstractSAXParser.java:737)
> 	at
> com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentSca
> nnerImpl.s
> canDocument(XMLDocumentFragmentScannerImpl.java:515)
> 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.
> parse(XML1
> 1Configuration.java:807)
> 	at
> com.sun.org.apache.xerces.internal.parsers.XML11Configuration.
> parse(XML1
> 1Configuration.java:737)
> 	at
> com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XML
> Parser.jav
> a:107)
> 	at
> com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.p
> arse(Abstr
> actSAXParser.java:1205)
> 
> --~------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@l...>
> --~--
> 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@l...>
--~--



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent