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 :
605
Xalan: The org.apache.xalan.xsltc.trax.SmartTransformerFactoryImpl Class
This
class is main implementation of transformer factory that uses an XSLTC
transformer for the creation of Templates objects and uses the Xalan processor
transformer factory for the creation of Transformer objects.
A
Template is the runtime representation of processed transformation
instructions. While using Templates
objects, you should ensure the Thread safety.
Method Overviews
This
class is the concrete implementation of transformer factory. I have given
examples of methods to create Templates object from an input source, how to
create a transformer factory to perform the transformation.
Example of newTemplates(javax.xml.transform.Source):
This
method is used to create a Templates object from a Source. Javax.xml.transform.Source
is an interface so you have to provide a concrete implementation of Source
interface. In my example I have used javax.xml.transform.stream.StreamSource.
StreamSource
source = new StreamSource(stylesheetURI);// stylesheetURI is the system URI for
your xsl stylesheet.
Example of newTransformer(javax.xml.transform.Source):
This
method is used to parse a javax.xml.transform.Transformer Object. Using javax.xml.transform.Transformer
object, you can do the actual transformation.
StreamSource
source = new StreamSource(stylesheetURI);// stylesheetURI represents the
stylesheet.
StreamSource
sourceXML = new StreamSource(xmlURI);// xmlURI represents system URI of your
input xml file.
StreamResult result = new
StreamResult(outURI);// outURI represents system URI of the output file.
If you
want the result of your transformer to be shown in your command prompt, then
you can use System.out while creating
Result.
StreamResult
result = new StreamResult(System.out);
transformer.transform(sourceXML,result);
Example of newTransformer():
This
method is used to create a Transformer object that copies the input document to
the result. Uses the rg.apache.xalan.processor.TransformerFactory.