xsl-list
[Top] [All Lists]

RE: Optimizing Trax

2003-06-20 11:24:53
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(_at_)koberg(_dot_)com]
Sent: Friday, June 20, 2003 10:49 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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(_at_)lists(_dot_)mulberrytech(_dot_)com 
[mailto:owner-xsl-
list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of Schwartz, Rechell 
R, ALABS
Sent: Friday, June 20, 2003 6:05 AM
To: XSL-List(_at_)lists(_dot_)mulberrytech(_dot_)com

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



<Prev in Thread] Current Thread [Next in Thread>