Java Reference
In-Depth Information
Exploring the XSLT API
Java implements XSLT through the types found in the javax.xml.transform ,
javax.xml.transform.dom , javax.xml.transform.sax ,
javax.xml.transform.stax , and javax.xml.transform.stream pack-
ages.The javax.xml.transform packagedefinesthegenericAPIsforprocessing
transformation instructions, and for performing a transformation from a source (where
theXSLTprocessor'sinputoriginates)toaresult(wheretheprocessor'soutputissent).
The remaining packages define the APIs for obtaining different kinds of sources and
results.
The javax.xml.transform.TransformerFactory class is the starting
pointforworkingwithXSLT.Youinstantiate TransformerFactory bycallingone
its newInstance() methods. The following example uses TransformerFact-
ory 's static TransformerFactory newInstance() method to create the
factory:
TransformerFactory tf = TransformerFactory.newInstance();
Behindthescenes, newInstance() followsanorderedlookupproceduretoidenti-
fy the TransformerFactory implementation class to load. This procedure first
examinesthe javax.xml.transform.TransformerFactory systemproperty,
and lastly chooses the Java platform's default TransformerFactory implement-
ation class when no other class is found. If an implementation class is not available
(perhaps the class identified by the
javax.xml.transform.TransformerFactory systempropertydoesn'texist)
or cannot be instantiated, newInstance() throws an instance of the
javax.xml.transform.TransformerFactoryConfigurationError
class. Otherwise, it instantiates the class and returns its instance.
Afterobtaininga TransformerFactory instance,youcancallvariousconfigur-
ation methods to configure the factory. For example, you could call Transformer-
Factory 's void setFeature(String name, boolean value) methodto
enable a feature (such as secure processing, to transform XML documents securely).
Followingthefactory'sconfiguration,calloneofits newTransformer() methods
to create and return instances of the javax.xml.transform.Transformer
class.Thefollowingexamplecalls Transformer newTransformer() toaccom-
plish this task:
Transformer t = tf.newTransformer();
Search WWH ::




Custom Search