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:
This program uses three arguments to take inputs from the command line: arg is for XML file, arg is for XSL file, and arg 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>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:
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.