|
| |
The Xalan-Java distribution includes a number of basic sample applications. These samples are easy to run, and you can review the source files -- all of which are brief -- to see just how they work.
To run the samples, do the following:
- Set up your class path (see above), including xalansamples.jar.
- Be sure the java executable is on your path.
- Go to the samples subdirectory containing the sample (use the DOS shell if you are running Windows).
- Use the java executable to run the sample from the command line.
- Examine the application source files.
For example, go to the SimpleTransform subdirectory and issue the following command:
java SimpleTransform
The sample displays the transformation result on the screen. To see how the example works, examine the source files: foo.xml, foo.xsl, and SimpleTransform.java.
The extensions examples require additional JAR files on the class path, and the procedure for running the sample applet and sample servlet is different. For more information about all the samples, see Xalan-Java Samples.
|
| | | | Setting up your own Java applications | | | | |
| |
You can start by using your own XML source files and XSL stylesheets with the sample applications, which illustrate a number of the basic usage patterns.
If you modify a java source file, be sure to compile the class and place it on the system class path. Here are some basic points to keep in mind as you are setting up transformations:
- Use the XSLTProcessorFactory static getProcessor() method to set up an XSLTProcessor interface object.
- Set up XSLTInputSource class objects for the XML input and XSL stylesheet. You can use a file name or URL, character streams, byte streams, or SAX input stream to instantiate an XSLTInputSource object.
If the XML document contains a stylesheet Processing Instruction (PI), you do not need to create a separate
XSLTInputSource object for an XSL stylesheet.
- For improved performance with a series of transformations, use the XSLTProcessor processStylesheet() method to compile the XSL stylesheet (the result is a StylesheetRoot class), and then use the StylesheetRoot process() method to perform the transformations.
Compiling the stylesheet is also useful when you need to get information from the stylesheet before the transformation occurs, for
instance, when you need to find out the output encoding in order to construct the right kind of Writer.
You must also compile the stylesheet if you are using the XSLTProcessor as a SAX document handler (see Generating and responding to SAX events).
- Set up an XSLTResultTarget class for the transformation output. You can use a file name or URL, character stream, byte stream, or SAX document handler to instantiate an XSLTResultTarget object.
- Use the XSLTProcessor process() method to perform the transformation, or the StylesheetRoot process() method to perform a series of transformations with the same stylesheet.
XSLTProcessor is thread-safe for one instance per thread. If you are using the same instance of XSLTProcessor to perform
more than one transformation, call the reset method between transformations. StylesheetRoot is multithread-safe, and a single instance may be used across threads. Accordingly, you can call a StylesheetRoot object process() method repeatedly without resetting the StyleSheetRoot.
For more information on setting up applications, see Basic Usage Patterns.
|
|
|