Now we will develop a class in Java that takes both XML and XSL file as an input and transforms them to generate a formatted HTML file.
Here is the source code of the SimpleXMLTransform.java:
import javax.xml.transform.ErrorListener;
|
This program uses three arguments to take inputs from the command line: arg[0] is for XML file, arg[1] is for XSL file, and arg[2] is for taking the name of the html file that will be generated after the transformation.
As in the earlier section, we have described the working process of XSLT APIs. First, this program creates an instance of the TransformerFactory class. The new instance of the Transformer class is created using an ? xslStream? instance of the StreamSource class. This instance of the Transformer class required for transformation to generate the formatted output as a result object. Its method transform(in,out) takes two arguments: the XML document as a source object and the result document as an output object in the form of HTML .
4. Compile and Run the Program
C:\nisha\xslt>javac SimpleXMLTransform.java C:\nisha\xslt>java SimpleXMLTransform emp.xml emp.xsl emp.html The generated HTML file is:emp.html |
The format of the generated output file ?emp.html? will look like this:
|
|
|
Recommend the tutorial |


Ask Questions? Discuss: Create a Java program using XSLT APIs View All Comments
Post your Comment