You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Simone Tripodi <si...@gmail.com> on 2008/10/16 10:33:53 UTC

[Xalan 2.7.1] Reusing pre-compiled Translet

Hi everybody,
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.
Best Regards,
Simone

Re: [Xalan 2.7.1] Reusing pre-compiled Translet

Posted by Simone Tripodi <si...@gmail.com>.
Hi Henry,
thank you very very much for your help and for the time you spent to reply me.
Thank you again, best regards,
Simone

2008/10/17 Henry Zongaro <zo...@ca.ibm.com>:
>
> Hi, Simone.
>
> "Simone Tripodi" <si...@gmail.com> wrote on 2008-10-17 10:05:50 AM:
>> So, I would like to ask you about some details: I pre-compiled a
>> stylesheet named "my-xslt.xsl" from command line, using the options
>>
>> -p my.xslt.package -o MyXslt
>>
>> so now I would like to know if the TransformerFactory
>>
>>     Transformer t = tf.newTransformer(new StreamSource("my-xslt.xsl"));
>>
>> will look for my.xslt.package. MyXslt class.
>> Can you explain me what will happen, please?
>
> XSLTC supports TransformerFactory attributes that allow you to specify the
> name for the translet class as well as the package.  So if you use the
> following code, the processor should use your pre-compiled
> my.xslt.package.MyXslt class.  By default, the classes are assumed to be in
> the default package with a class name derived from the system ID.
>
> tf.setAttribute("translet-name", "MyXslt");
> tf.setAttribute("package-name", "my.xslt.package");
> Transformer t = tf.newTransformer(new
> StreamSource("randomstylesheetname.xsl"));
>
> I hope that helps.
>
> Thanks,
>
> Henry
> ------------------------------------------------------------------
> Henry Zongaro
> XML Transformation & Query Development
> IBM Toronto Lab   T/L 313-6044;  Phone +1 905 413-6044
> mailto:zongaro@ca.ibm.com
>
>



-- 
My LinkedIn profile: http://www.linkedin.com/in/simonetripodi
My GoogleCode profile: http://code.google.com/u/simone.tripodi/
My Picasa: http://picasaweb.google.com/simone.tripodi/
My Tube: http://www.youtube.com/user/stripodi
My Del.icio.us: http://del.icio.us/simone.tripodi

Re: [Xalan 2.7.1] Reusing pre-compiled Translet

Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Simone.

"Simone Tripodi" <si...@gmail.com> wrote on 2008-10-17 10:05:50 
AM:
> So, I would like to ask you about some details: I pre-compiled a
> stylesheet named "my-xslt.xsl" from command line, using the options
> 
> -p my.xslt.package -o MyXslt
> 
> so now I would like to know if the TransformerFactory
> 
>     Transformer t = tf.newTransformer(new StreamSource("my-xslt.xsl"));
> 
> will look for my.xslt.package. MyXslt class.
> Can you explain me what will happen, please?

XSLTC supports TransformerFactory attributes that allow you to specify the 
name for the translet class as well as the package.  So if you use the 
following code, the processor should use your pre-compiled 
my.xslt.package.MyXslt class.  By default, the classes are assumed to be 
in the default package with a class name derived from the system ID.

tf.setAttribute("translet-name", "MyXslt");
tf.setAttribute("package-name", "my.xslt.package");
Transformer t = tf.newTransformer(new 
StreamSource("randomstylesheetname.xsl"));

I hope that helps.

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro
XML Transformation & Query Development
IBM Toronto Lab   T/L 313-6044;  Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com


Re: [Xalan 2.7.1] Reusing pre-compiled Translet

Posted by Simone Tripodi <si...@gmail.com>.
Hi Henry,
thank you for your reply!

Well, the tense

// Will look for a class named "MyXslt" without recompiling

clarified me a lot of troubles, thank you very very much.

So, I would like to ask you about some details: I pre-compiled a
stylesheet named "my-xslt.xsl" from command line, using the options

-p my.xslt.package -o MyXslt

so now I would like to know if the TransformerFactory

    Transformer t = tf.newTransformer(new StreamSource("my-xslt.xsl"));

will look for my.xslt.package. MyXslt class.
Can you explain me what will happen, please?
Thank you very much in advance, best regards

Simone


2008/10/17 Henry Zongaro <zo...@ca.ibm.com>:
>
> Hi, Simone.
>
> "Simone Tripodi" <si...@gmail.com> 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:zongaro@ca.ibm.com
>



-- 
My LinkedIn profile: http://www.linkedin.com/in/simonetripodi
My GoogleCode profile: http://code.google.com/u/simone.tripodi/
My Picasa: http://picasaweb.google.com/simone.tripodi/
My Tube: http://www.youtube.com/user/stripodi
My Del.icio.us: http://del.icio.us/simone.tripodi

Re: [Xalan 2.7.1] Reusing pre-compiled Translet

Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Simone.

"Simone Tripodi" <si...@gmail.com> 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:zongaro@ca.ibm.com