RE: [xsl] Chaining Transformers/Templates

Subject: RE: [xsl] Chaining Transformers/Templates
From: "Varley, Roger" <Roger.Varley@xxxxxxxxxxx>
Date: Tue, 10 Dec 2002 14:55:36 -0000
> 
> Two of the classes mentioned, XMLReaderFactory and SerializerFactory,
> aren't in JAXP: any reason why you're not writing pure JAXP code?
> 

Again, probably newbie-itis as far as XSLT is concerned. The first example I
found in Wrox's "Professional Java XML" uses these classes. Probably by the
time I get to the end, I'll find other/better ways of doing it :)

> The XMLReader and the TransformerHandlers are serially 
> reusable but not
> multithreaded. It's generally best to create a new instance of these
> classes for each transformation, if only to be sure of clearing out
> unwanted data in memory. The important object to reuse is the 
> Templates
> object.
> 

What if I cloned newly created XMLReader and returned that?

Thanks again

Roger

 
> 
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> > Varley, Roger
> > Sent: 10 December 2002 13:01
> > To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> > Subject: RE: [xsl] Chaining Transformers/Templates
> > 
> > 
> > > 
> > > > The reason that I want to to use Templates is that I
> > > > will have a large number of threads performing a 
> > > > transormations using two standard XSL stylesheets so I want 
> > > > to avoid the overhead of re-processing the transform 
> > > > instructions every time. 
> > 
> > Thanks to Micheal Kays response I now have the following code 
> > running and working in the processing threads.
> > 
> >            TransformerFactory tFactory = 
> > TransformerFactory.newInstance();
> >            SAXTransformerFactory saxFactory = 
> > (SAXTransformerFactory) tFactory;
> >            
> >            TransformerHandler standardTH = 
> > saxFactory.newTransformerHandler(standardTemplate);
> >            TransformerHandler recipientTH = 
> > saxFactory.newTransformerHandler(recipientTemplate);
> >            
> >            XMLReader reader = XMLReaderFactory.createXMLReader();
> >            reader.setContentHandler(standardTH);
> >            standardTH.setResult(new SAXResult(recipientTH));
> >            
> >            Serializer serializer = 
> > SerializerFactory.getSerializer(OutputProperties.getDefaultMet
> > hodProperties(
> > "xml"));
> >            serializer.setOutputStream(new 
> > FileOutputStream(incomingPath + "result.xml"));
> >            
> >            recipientTH.setResult(new 
> > SAXResult(serializer.asContentHandler())); 
> > 
> > The template objects are created by an external singleton 
> > class called by the processing thread. The singleton class 
> has to call
> > TransformerFactory.newInstance() to create the template, so 
> > I'm now wondering how much of the above code I can move to my 
> > external singleton class and still remain threadsafe. For 
> > example, could I go as far as moving all this code to my 
> > external class so that the XMLReader is only built once and 
> > return the XMLReader object to every thread that asks for it. 
> > The thread then builds the input for the XMLReader and then 
> > calls XMLReader.parse().
> > 
> > Regards
> > Roger 
> > 
> >  XSL-List info and archive:  
http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread