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.
TransformerFactory
is an abstract class. It has a static method netInstance() to create an
instance of TransformerFactory. This method instantiates the concrete subclass
designated by the javax.xml.transform.TransformerFactory system property.
The default setting for this system property is org.apache.xalan.processor.TransformerFactoryImpl.
Use instance of TransformerFactory to
get an instance of javax.xml.transform.Transformer from your stylesheet
source.
The TransformerFactory’s newTransformer(Source xslSource)
method processes the stylesheet Source into a Templates object and returns a
Transformer that you can use to perform a transformation. You can provide
different input sources to this method.
You can provide a
DOMSource
You can provide a StreamSource
You can also provide a
SAXSource
StreamSource source = new StreamSource(stylesheetURI);
Perform the
transformation using javax.xml.transform.Transformer
instance.
Use the Transformer transform(Source xmlSource, Result
transformResult) method to transform the XML Source and place the
transformation output in a Result object.
Like Step2, you can supply the XML Source in the form of a StreamSource,
DOMSource, or SAXSource. Likewise, the Result may be a StreamResult, DOMResult,
or SAXResult.
StreamSource sourceXML = new StreamSource(xmlfileURI);
StreamResult result = new StreamResult(outURI);
transformer.transform(sourceXML, result);
Note: If you plan to use the stylesheet Source to transform
multiple XML Sources, you should use the TransformerFactory newTemplates(Source
xslSource) method to explicitly generate a Templates object. For each
transformation, use the Templates object to generate a new Transformer.