I've found the sample servlet XSLTServletWithParams.java to 
be very helpful. I modified the following block in an attempt
to implement a template for performance gains, but have a 
feeling that I'm missing something.  

        if (xslSource != null) // Now do we have a stylesheet?
        {
          Templates templates = tFactory.newTemplates(xslSource);
          transformer = templates.newTransformer();
          setParameters(transformer, request); // Set stylesheet params.
          // Perform the transformation.
          transformer.transform(xmlSource, new StreamResult(out)); 
        }

Should I put a declaration such as the following outside the doPost?

    private static Templates templates = null;

And then have a test within the above block such as 

        if (templates == null){
          Templates templates = tFactory.newTemplates(xslSource);
        }

Otherwise, I suspect every time a user hits the servlet it recreates
the templates object, thus adversely affecting performance. 

FYI - My servlet implementation is applying the same XSL stylesheet to 
the same XML document over and over with different parameters 
to change the resulting html.

Tom

Reply via email to