jd.xslt - Programming Guide
The jd.xslt packages contain several hundred classes but you only need to know a handful of them
to integrate the XSLT processor into your Java program.
If you use SUN's TrAX API you can even skip these since jd.xslt
offers a TrAX implementation as described below.
jd.xml.xslt.Stylesheet - represents a XSL Stylesheet.
- Instantiate a Stylesheet object for a XSL file and call its transform-method to
transform a XML document.
- If several XML documents are transformed with the same stylesheet, it is a good idea
to reuse the (threadsafe) Stylesheet object to save the time for parsing the XSL file again and again.
- XML and XSL documents are specified by a XmlSource object passed to the
setup and the transform-method.
- The output document is specified by a XsltResult object passed to the transform-method.
- Use the method setUriResolver(UriResolver) to set a custom UriResolver
- Use the method setParameter(String name, Object value) to set the value of a top-level parameter.
jd.xml.util.XmlSource -
represents the source of a XML document.
- Similar to org.xml.sax.InputSource a XmlSource encapsulates the various possibilities
to specify the source of a XML document:
The constructors of XmlSource accept a file name, a File, InputStream, URL or a DOM document.
(The last option allows you to transform DOM documents which are already kept in memory).
- Additionaly a XmlSource requires to specify the uri of the source which is used
as a base uri to resolve relative references to other documents.
- The stylesheet-methods setup) and transform expect XmlSource arguments that specify
the source of the stylesheet and the input document.
jd.xml.xslt.XsltResult - represents the result of a XSL transformation.
- XsltResult encapsulates (like XmlSource) the different possibilities
for the result of a transformation. Its constructor accept a File, an OutputStream or a
ResultBuilder as parameter.
jd.xml.xslt.XsltException
- Is thrown if an error during the transformation occurs.
- If the error is caused by another exception, this exception can be retrieved from
the XsltException.
jd.xml.xslt.parser.XsltParseException
- Is thrown if an error during the parsing of the stylesheet occurs.
- If the error is caused by another exception, this exception can be retrieved from
the XsltParseException.
jd.xml.util.UriResolver
- a helper class to resolve an uri from a base uri and a relative uri.
- an UriResolver can be set via Stylesheet.setUriResolver. It is then used to process
xsl:import, xsl:include instructions or a call to the document-function.
jd.xml.xslt.TransformationChain -
represents a list of transformations
- TransformationChain allows to apply several transformations to a XML document.
- Can be invoked from the command line.
jd.xml.xslt.trax.TransformerFactoryImpl
- an implementation of
javax.xml.transform.TransformerFactory
which lets you invoke the jd.xslt processor via SUN's TrAX (Transformation API for XML):
- Here is a code fragment on how to use the API:
import java.io.*;
import javax.xml.transform.*;
...
System.setProperty("javax.xml.transform.TransformerFactory",
"jd.xml.xslt.trax.TransformerFactoryImpl");
TransformerFactory tfactory = TransformerFactory.newInstance();
Source stylesheetSource = ...
Transformer transformer = tfactory.newTransformer(stylesheetSource);
transformer.transform(...);
jd.xml.xslt.XsltSecurityManager
- XsltSecurityManager is a class that allows applications to implement a security
policy for XSLT transformations: It can restrict
- the execution of xsl:script instructions
- the creation of subdocuments by the xsl:document instruction
- the reading of documents by the xsl:document function
- To implement your security policy derive a class from XsltSecurityManager, override
its methods and employ it by calling
XsltSecurityManager.setGlobalInstance
or
Stylesheet.setSecurityManager
main page