Glenn (and everybody else wanting to use XSLTC with TrAX),

> I am using XSLTC to precompile XSL stylesheets into Translets during
> the build process.  But also want the ability to seamlessly replace
> a precompiled Translet with a Templates object generated at runtime
> from an XSL stylesheet loaded from file. The TemplatesImpl() class
> was the only way I could find to easily instantiate a precompiled
> Translet class as a Templates object. 

I understand what you are saying here, but you still cannot use our
internal classes that are supposed to be plugged in behind TrAX.
The whole idea behind the JAXP/TrAX API is that you use the defined
API only, and that the only thing that links your code to our
implementation is the "javax.xml.transform.TransformerFactory"
property. You are not to call any of the TrAX implementation classes
directly. The fact that we have (by mistake) made some of these
classes public is a mistake that can be misleading. I appoligise
for that and will take care of that shortly.

Now, on to the next issue:
> I don't see a way to instantiate a precompiled Translet class as
> a Templates object using TraX, I would love to be wrong on this.

Well, I think you are in for a positive surprise. The translet class
file(s) are stored inside the Templates object. This means that by
writing the Templates class to disk you in effect store the translet
class (including auxiliary classes). This object can be read back
from disk and used to instanciate Transformer objects. This is all
demonstrated in the sample code in the Xalan package:

    xml-xalan/java/samples/CompiledJAXP

I'll give you a short description here:

    // Get an input stream for the XSL stylesheet
    StreamSource stylesheet = new StreamSource(xsl_file);

    // The TransformerFactory will compile the stylesheet and
    // put the translet classes inside the Templates object
    TransformerFactory factory = TransformerFactory.newInstance();
    Templates templates = factory.newTemplates(stylesheet);

    // Send the Templates object to a '.translet' file
    dumpTemplate(getBaseName(xsl_file)+".translet", templates);

The 'dumpTemplate()' method writes the Templates object to a file
using serialization. Then, to read back the translet and run a
transformation you do this:

    // Get a placeholder for the input and output documents
    StreamSource document = new StreamSource(xml_file);
    StreamResult result = new StreamResult(System.out);

    // Read the Templates object back from disk
    Templates templates = readTemplates(translet_file);

    // Instanciate a Transformer and run the transformation
    Transformer transformer = templates.newTransformer();
    transformer.transform(document, result);

Note that all this is done using the standard TrAX API.

Morten


Glenn Nielsen wrote:
> 
> Morten Jorgensen wrote:
> >
> > Glenn,
> >
> > There is only one way in which you can instanciate a Templates object,
> > and that is by running "newTemplates(Source src)" on the transformer
> > factory. Once this Templates object is created it can then be cached
> > in memory, or on disk (using serialization). This is all demonstrated
> > in our "CompiledJAXP" example.
> >
> > When using TrAX you should stick to what is documented in the TrAX
> > API. I don't know what convinced you to use the internal interface of
> > our TrAX implementation.
> >
> 
> I am using XSLTC to precompile XSL stylesheets into Translets during
> the build process.  But also want the ability to seamlessly replace
> a precompiled Translet with a Templates object generated at runtime from
> an XSL stylesheet loaded from file.  The TemplatesImpl() class was the
> only way I could find to easily instantiate a precompiled Translet class
> as a Templates object.  I know I could have Xalan compile stylesheets at
> runtime into Translets by setting a jaxp property, but that adds a great
> deal more overhead at servlet init time.  I don't see a way to instantiate
> a precompiled Translet class as a Templates object using TraX, I would
> love to be wrong on this.
> 
> Regards,
> 
> Glenn
> 
> > Thanks,
> > Morten
> >
> > Glenn Nielsen wrote:
> > >
> > > I reimplemented use of precompiled Translet's using Xalan 2.2 D9.
> > >
> > > This snippet of code allows me to create a Template from a translet
> > > class name.
> > >
> > > template = (Templates)new TemplatesImpl(null,translet);
> > >
> > > It isn't clear from the java docs for TemplatesImpl that you can pass
> > > in either the byte codes or the translet class name.
> > >
> > > So the precompiled Translet's can be instantiated as a Templates object.
> > > But I have found that a number of XSL stylesheets I tried did not work
> > > correctly as a precompiled Translet.
> > >
> > > Regards,
> > >
> > > Glenn
> 
> --
> ----------------------------------------------------------------------
> Glenn Nielsen             [EMAIL PROTECTED] | /* Spelin donut madder    |
> MOREnet System Programming               |  * if iz ina coment.      |
> Missouri Research and Education Network  |  */                       |
> ----------------------------------------------------------------------

-- 
 
Morten J�rgensen

E-mail: [EMAIL PROTECTED]
Phone:  +353 1 819 9071 / x-19071
--8<-----------------------------------------------------------
C'est l'histoire d'un mec qui tombe d'un immeuble de cinquante 
�tages. A chaque �tage, a fur et � mesure de sa chute, il se r�p�te 
sans cesse pour se rassurer:
        Jusqu'ici tout va bien,
        jusqu'ici tout va bien,
        jusqu'ici tout va bien...
Mais l'important, c'est pas la chute, c'est l'atterrissage.

Reply via email to