> I asked a question on an MVC application architecture using XLS, and got advice to
> cache XLS / XSLT style sheets, and pre compile them.

Sounds like something I would say...

> Can someone give me some more background on this.

Hope so.

> How?

The code we use is totally tied to Xalan, but can easily be generalized
with newer APIs. The following code will "compile" a stylesheet, and
write the compiled stylesheet (a StylesheetRoot object in our case) to
a file:

   String sysId = "file:/path/to/style/sheet/file.xsl";
   FileInputStream styleSheetIn = new FileInputStream( ... );
   ObjectOutputStream serialOut = new ObjectOutputStream( ... );
   XSLTInputSource xSrc = new XSLTInputSource( styleSheetIn );
   xSrc.setSystemId( sysId );
   StylesheetRoot root = processor.processStylesheet( xSrc );
   serialOut.write( root );

The SystemId is necessary so that Xalan can find me <xsl:include> files.

Our servlet code, in turn, then loads the compiled stylesheet with code
that looks like this:

   XSLTProcessor processor =
      XSLTProcessorFactory.getProcessorUsingLiaisonName
         ( "org.apache.xalan.xpath.xdom.XercesLiaison" );

   ObjectOutputStream serialOut = new ObjectOutputStream( ... );
   StylesheetRoot compiledStyleSheet = serialIn.readObject();

Once the stylesheet is loaded, we can use it in a call to process:

   compiledStyleSheet.process( processor, xmlSource, htmlOut );

> What if the content is dynamic? (2 million items and 100,000  of styles + with any 
>combination)

I am not sure what this means.

Are you saying that your XSL stylesheets are dynamic?
Or are you describing your XML tree?

When you say 100,000 of styles, what does that mean?

tim.


Reply via email to