RE: [xsl] Optimizing Trax

Subject: RE: [xsl] Optimizing Trax
From: Rob Rohan <me@xxxxxxxxxxxx>
Date: 20 Jun 2003 12:51:49 -0700
On Fri, 2003-06-20 at 12:22, Schwartz, Rechell R, ALABS wrote:
> How do I tranform the document using SAX-- i.e., how do I change this
> line?
> 
>  transformer.transform(new DOMSource(document), new StreamResult(out));
> 
This is kind of more a java question than an XSLT question. Here is a
snip-it that I use in one of my programs - it's a touch kludgey but if
you know java you can decipher the needed parts - if you can't I
recommend "Java & XML" second edition by Brett McLaughlin from O'Reilly

public long transform(java.io.InputStream xmlin, java.io.InputStream
xslin, java.io.OutputStream output, java.io.File xslURI, java.io.File
xmlURI) throws Exception {
       
	strResult = null;
	if(params == null)
		params = new Vector();
	   
       String media = null;
       
       //set the factory to the specified one       
	System.setProperty("javax.xml.transform.TransformerFactory",  XSLTFactory);
              
       //get an instance and make a result object       
	tfactory = javax.xml.transform.TransformerFactory.newInstance();
       
	strResult = new javax.xml.transform.stream.StreamResult(output);
       
	stf = (javax.xml.transform.sax.SAXTransformerFactory) tfactory;
           
       StreamSource ss = new StreamSource(xslin);
       if(xslURI != null) ss.setSystemId(xslURI);
       
       stylesheet = tfactory.newTemplates(ss);
       
       transformer = stylesheet.newTransformer();

       //set params       
	for(int i=0; i < params.size()-1; i++)
        	transformer.setParameter((String) params.elementAt(i), (String)params.elementAt(i+1));

        //do the transformation  
	StreamSource input = new StreamSource(xmlin);
        if(xmlURI != null) input.setSystemId(xmlURI);

     
        transformer.transform(input, strResult);
....


> Rechell Schwartz
> 
> -----Original Message-----
> From: J.Pietschmann [mailto:j3322ptm@xxxxxxxx]
> Sent: Friday, June 20, 2003 3:13 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] Optimizing Trax
> 
> 
> Schwartz, Rechell R, ALABS wrote:
> > I am using Trax to transform my xml files, and am finding the
> performance
> > very slow especially for large files. Are there any ways of optimizing
> the
> > performance such as by pre-compiling the stylesheets?
> 
> Yes, but your time is probably wasted elsewhere.
> 
> 
>  > transformer = tFactory.newTransformer(new 
> StreamSource(getClass().getResourceAsStream(xsl)));
>  > transformer.transform(new DOMSource(document), new
> StreamResult(out));
>                               ^^^^^^^^^^^^^^^^
> Use a profiler to check where your program wastes time:
> - DB access or whereever you get your raw data
> - DOM construction
> - transformation
> If it is the latter, check your XSL for inefficient constructs.
> If it is DOM construction, use SAX. Also DOM uses a lot of memory,
> which may be a problem in itself (more GC).
> 
> J.Pietschmann
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
-- 
   ´¨)
 ¸.·´¸.·´¨)    ¸.·´¨)
(¸.·´    (¸.·´   .·´ ¨¨°º©Rob Rohan©º°¨¨°º ¨¨°º©?

http://treebeard.sourceforge.net
http://ashpool.sourceforge.net

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.2.1 (GNU/Linux)

mQGiBD7mjIMRBADXYdJqgG5q6/aZ8jrTkhJ3Hu6c9J0CNGfFUbGikoNXmBmQ/1Q/
ECvrOhjuxreCzO+KobVWN6TljbVyUSWbyQrvbFg4KzNE3Dy+hpxei4UQ0jc8VNG1
CNxizn+NWU/WMiRZx+iVkj+X65n3hfK2uPqj1xyw0409WN2myJEwAmuVpwCghQMa
iOb4pbngjmGlH6kWyhn+GHkEAIx59mhslaSInjI6lNRfTxOjAPi4QqOTGpNiN0JE
VfJIsoFMv13c8eckMpTvG+YC1UzifkwOSSQr/niwH0yaZjlouBJj/CkZdCUyFojz
NdnkpgBmzpS3qN9fkdwe2jdWh4Xr3MU7uHHfrLlyOh5/P4ocuUDXYnI8oRj1YQCk
NbrYA/4uyUCdKBV0bMRrL/njv1hyZ7FBNPtsfVv1yeO/r/xHeoVGeL+e0RPYaACH
+OVJWeutp1BTbmRcpHybMxqV5WdCFP4wb2M7q2Ho4t/YvCMZn6Wr6UoPqVd6qodn
eoQkoRH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berrytech.com/xsl/xsl-list


Current Thread