BizTalk Utilities CV ,   Jobs ,   Code library  
 
Home Page
XALAN
The Usage of XALAN
Overview of XALAN - Java
<< WCF, WS, SOAP
XHTML >>

By :Mark Wilson
I am the creator of TopXML. I am available for international and local (Australia) contracts. I am a Solution Architect/Business Analyst. I have worked in IT in several countries (NZ, Australia, South Africa, UK) building and training teams for government and very large non-governmental organizations. I am ex-Microsoft Consulting Services. I wrote the first book on Microsoft XML published in 2000 called XML Programming with VB and ASP. Most recently I have been building tools for the SEO industry. Ask me for a 37 point SEO health-checkup for your website.
First posted :03/24/2008
Times viewed :685

 

Xalan: XSLTC

XSLTC provides API to compile a stylesheet to generate compiled version of stylesheet(called translets) and processor to apply compiled version of stylesheet(translets) on xml to produce output(.html/.xml/.wml).

Flow of XSLTC

In the above diagram, XSLTC provides compiler which compiles stylesheets and produces translets. XSLTC also provides runtime processor which applies translets on xml document and transforms into desired output.

Note: To compile and run translets, you should have JRE 1.2 and above.

Setting upon your classpath

Previously XSLTC classes are coming with xsltc.jar so other required jar file to be added to system classpath. If you are running with original XSLTC, then ensure that all required jar files also added in your system classpath.

Now, a single xalan.jar contains the code for both Xalan-Java processors. You can use the JAXP javax.xml.transform.TransformerFactory property to select which processor to use: the Interpretive or the Compiling processor.

Compiling Translets from Commandline

XSLT Compiler is a java based utility, that compiles stylesheets and produces a lightweight and portable Java byte codes called translets.

Usage:

java org.apache.xalan.xsltc.cmdline.Compile hello.xslt

The above utility will produce hello.class translet file.

To know different usage of java org.apache.xalan.xsltc.cmdline.Compile, just run it without giving any argument.

If you run java org.apache.xalan.xsltc.cmdline.Compile, the output would be

XSLTC version 1.4

SYNOPSIS

   java org.apache.xalan.xsltc.cmdline.Compile [-o <output>]

      [-d <directory>] [-j <jarfile>] [-p <package>]

      [-n] [-x] [-s] [-u] [-v] [-h] { <stylesheet> | -i }

 

OPTIONS

   -o <output>    assigns the name <output> to the generated

                  translet.  By default the translet name is

                  derived from the <stylesheet> name.  This option

                  is ignored if compiling multiple stylesheets.

   -d <directory> specifies a destination directory for translet

   -j <jarfile>   packages translet classes into a jar file of the

                  name specified as <jarfile>

   -p <package>   specifies a package name prefix for all generated

                  translet classes.

   -n             enables template inlining (default behavior better

                  on average).

   -x             turns on additional debugging message output

   -s             disables calling System.exit

   -u             interprets <stylesheet> arguments as URLs

   -i             forces compiler to read stylesheet from stdin

   -v             prints the version of the compiler

   -h             prints this usage statement

 

If you want XSLT Compiler to produce a jar file containing translets then use following option:

java org.apache.xalan.xsltc.cmdline.Compile

 -j hello.jar hello.xsl

If you want to specify a particular name for your translet file, then use following option:

java org.apache.xalan.xsltc.cmdline.Compile

 -o mytranslet hello.xsl

The above utility will produce a mytranslet.class file. This is the name of your translet.

You can try using different options.

Note: To run XSLT compiler, ensure that you have required jar files(xalan.jar, xml-apis.jar and xercesImpl.jar) in your classpath.

Running translets from Commandline

The XSLTC runtime processor is a Java-based tool for transforming XML document files using a translet (compiled stylesheet).

java org.apache.xalan.xsltc.cmdline.Transform person.xml mytranslet

Note: Ensure that your translet file is in your classpath.

Use XSLTC with JAXP1.2

To use the JAXP 1.2 API to perform transformations with translets do the following:

  1. Set the javax.xml.transform.TransformerFactory system property as indicated above.
  2. Instantiate a TransformerFactory.
  3. Instantiate a Transformer object either directly from the TransformerFactory or through a Templates object. A Transformer is a processed instance of a stylesheet (a translet) that can be used to perform a transformation. See below for more information on when you should use a Templates object.
  4. Perform the transformation, using a StreamSource object for the XML input and a StreamResult object to hold the transformation output.

Both a Templates object and a Tranformer object are processed representations of a stylesheet, but you cannot use a Templates object to perform transformations. Instead, you can use a Templates object to create new Transformer instances, without having to reprocess the stylesheet each time. You can use a TransformerFactory to generate a Templates object or a Transformer object directly. You can use a Transformer more than once, but you cannot use it concurrently on more than one thread. If you need to use the same stylesheet to perform transformations on more than one thread at the same time, use a Templates object and create as many Transformer objects as you require.

XSLTC also defines a set of attributes that you can set on the TransformerFactory in order to save and subsequently use those translets by way of the JAXP Transform API - without having to recompile the stylesheet each time.


Rate this article on a scale of 1 to 10

Your vote :  


 

Recent Jobs

A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En
A Greate Opportunituy as a SQL Deve
An immediate job opportunity as a B

View all Jobs (Add yours)
View all CV (Add yours)



chicago web site design
spfxmasks
Host Department NOLIMIT Web Hosting
Domain Names UK
Prada sunglasses
New York Pool Contractor
answering service
conference calling
swimming pool builder
MSN
sunglasses


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP