2

I am producing compiled .class files (Translet) from XSL transformation files with using TransformerFactory which is implemented by org.apache.xalan.xsltc.trax.TransformerFactoryImpl.

Unfortunately, I couldn't find the way how to use these translet classes on XML transformation despite my searchings for hours.

Is there any code example or reference documentation may you give? Because this document is insufficient and complicated. Thanks.

kursattokpinar
  • 119
  • 1
  • 8
  • Provide the code how you create your Translets and how you use it for the moment. (might include /* here I'm stuck */) – stwissel Apr 23 '14 at 03:52

1 Answers1

1

A standard transformation in XSLT looks like this:

    public void translate(InputStream xmlStream, InputStream styleStream, OutputStream resultStream) {
        Source source = new StreamSource(xmlStream);
        Source style = new StreamSource(styleStream);
        Result result = new StreamResult(resultStream);

        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer t = tFactory.newTransformer(style);
        t.transform(source, result);
    }

so given that you don't use a Transformer factory, but a ready made Java class (which is an additional maintenance headache and doesn't give you that much better performance since you can keep your transformer object after the initial compilation) the same function would look like this:

    public void translate(InputStream xmlStream, OutputStream resultStream) {
        Source source = new StreamSource(xmlStream);
        Result result = new StreamResult(resultStream);

        Translet t = new YourTransletClass();
        t.transform(source, result);
    }

In your search you missed out to type the Interface specification into Google where the 3rd link shows the interface definition, that has the same call signature as Transformer. So you can swap a transformer object for your custom object (or keep your transformer objects in memory for reuse)

Hope that helps

stwissel
  • 20,110
  • 6
  • 54
  • 101
  • thanks @stwissel 3rd link may be different in our searches, i applied your answer and i found the same solution in samples files of xalan 2.7.1 download files – kursattokpinar Apr 25 '14 at 06:23