[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Optimizing Trax


Subject: RE: [xsl] Optimizing Trax
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Sat, 21 Jun 2003 15:22:49 +0100

You are still compiling the stylesheet (newTemplates()) every time you
execute it.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Schwartz, Rechell R, ALABS
> Sent: 20 June 2003 19:25
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Optimizing Trax
> 
> 
> Rob,
> 
> I found the following code on-line, but it didn't improve the 
> performance at all. The xml file that is compiled is always 
> dynamic, while the xsl file is static. Any idea what could be wrong.
> 
> Rechell Schwartz
> 
>  public XslTransformer (String theXslFileName) 
>         throws TransformerConfigurationException
>     {
>         xslFileName  = theXslFileName;
>         
>         Templates templates = (Templates)CACHE.get(theXslFileName);
>         if (templates == null)
>         {
>             TransformerFactory factory = 
> TransformerFactory.newInstance();
> 
>           	templates = factory.newTemplates(new 
> StreamSource(xslFileName));
> 
>             CACHE.put(theXslFileName, templates);
>         } 
>         transformer  = templates.newTransformer();
>     }
> 
> -----Original Message-----
> From: Robert Koberg [mailto:rob@xxxxxxxxxx]
> Sent: Friday, June 20, 2003 10:49 AM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Optimizing Trax
> 
> 
> Hi,
> 
> You want to create javax.xml.transform.Templates objects and 
> keep a cache of these to retrieve the next time it is needed. 
> You will probably want to check if the source XSL (and 
> perhaps any dependencies - xsl:include/import's
> document() xml) has changed to reset the cache for a specific 
> Templates object.
> 
> There are examples of how to do this out there (google). 
> There are a couple of examples (one simple and one a little 
> more complex - they don't check for dependencies, though) in 
> O'Reilly's Java and XSLT (it think it is online somewhere).
> 
> If you are doing this offline you can use the Ant xslt task 
> which gives you the option of caching the template (you could 
> check out the src to see how they do it. Even if doing it in 
> a servlet environment you could use the task there too. 
> However in its current state it does not check for dependencies.
> 
> Best,
> -Rob
> 
> > -----Original Message-----
> > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl- 
> > list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Schwartz, Rechell R, ALABS
> > Sent: Friday, June 20, 2003 6:05 AM
> > To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
> > 
> > All,
> > 
> > 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? If so, how can
> this
> > be done?
> > Here is the code that is slow:
> > xsl = "/stylesheet.xsl";
> > transformer = tFactory.newTransformer(new 
> > StreamSource(getClass().getResourceAsStream(xsl)));
> > transformer.transform(new DOMSource(document), new 
> StreamResult(out));
> > 
> > Rechell Schwartz
> > 
> > 
> >  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
> 


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



Current Thread
Keywords