Hi, Simone. "Simone Tripodi" <[EMAIL PROTECTED]> wrote on 2008-10-16 04:33:53 AM: > I'm quite new with XSLTC and, even if I've also read the > documentation, I didn't understand how to reuse a pre-compiled XSLT: > to be clear, starting from an XSLT myxslt.xsl, I used the command line > to compile it in java class MyXslt.class. > Now, how can I use the MyXslt class in TrAX APIs? > Any suggestion will be very appreciated, thanks in advance.
There are three steps involved: 1. Include the generated classes on your class path 2. Specify that you want to use XSLTC's TransformerFactoryImpl class as the provider of the javax.xml.transform.TransformerFactory service. See [1] for details. 3. Set the "use-classpath" TransformerFactory attribute to true. See [2]. There are a number of ways to do step 2 - you could set the "javax.xml.transform.TransformerFactory" system property with the value "org.apache.xalan.xsltc.trax.TransformerFactoryImpl" either from the command-line or within your application. For instance, java -Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.TransformerFactoryImpl MyApplication Then when you create a TransformerFactory instance, you will get XSLTC's TransformerFactory implementation. Then step 3 direct the processor to derive the name of the classes required for the stylesheet from the system ID of the stylesheet, without recompiling the stylesheet. So, something like this should do it: TransformerFactory tf = null; try { tf = TransformerFactory.newInstance(); try { tf.setAttribute("use-classpath", Boolean.TRUE); } catch (IllegalArgumentException iae) { System.err.println("Processor didn't recognize \"use-classpath\" attribute"); } // Will look for a class named "MyXslt" without recompiling Transformer t = tf.newTransformer(new StreamSource("MyXslt.xsl")); t.transform(new StreamSource("input.xml"), new StreamResult(System.out)); } catch (TransformerConfigurationException tce) { System.err.println("Could not create Transformer"); } catch (TransformerException te) { System.err.println("Transform failed"); } I hope that helps. Thanks, Henry [1] http://xml.apache.org/xalan-j/usagepatterns.html#plug [2] http://xml.apache.org/xalan-j/xsltc_usage.html#api-attributes ------------------------------------------------------------------ Henry Zongaro XML Transformation & Query Development IBM Toronto Lab T/L 313-6044; Phone +1 905 413-6044 mailto:[EMAIL PROTECTED]