What i've done is to compile the template during the init.  and next i
reuse the template using templates.newTransformer();

Jean-Jacques Borie
Directeur recherche et d�veloppement

Tekora, changez votre conception des sites web
http://www.tekora.com
17, place de la R�sistance - 92130 Issy-les-Moulineaux
T�l. : +33 1 55 00 10 03 - Fax : +33 1 55 00 10 10
Por: +33 660199524
[EMAIL PROTECTED]





                                                                                       
                                                      
                    Tom Amiro                                                          
                                                      
                    <Tom.Amiro@Su        To:     "[EMAIL PROTECTED]" 
<[EMAIL PROTECTED]>                                       
                    n.COM>               cc:                                           
                                                      
                                         Subject:     example of using templates 
object in a servlet                                         
                    27/09/2001                                                         
                                                      
                    15:19                                                              
                                                      
                    Please                                                             
                                                      
                    respond to                                                         
                                                      
                    xalan-dev                                                          
                                                      
                                                                                       
                                                      
                                                                                       
                                                      




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