|
Introduction to XSL |
|
StreamSource in = new
StreamSource(inXML);
StreamResult out = new
StreamResult(outTXT);
transformer.transform(in,out);
System.out.println(“The generated HTML
file is:” + outTXT);
}
}
class MyErrorListener implements
ErrorListener {
public void warning(TransformerException
e)
throws TransformerException {
show(“Warning”,e);
throw(e);
}
public void error(TransformerException e)
throws TransformerException {
show(“Error”,e);
throw(e);
}
public void fatalError(TransformerException
e)
throws TransformerException {
show(“Fatal Error”,e);
throw(e);
}
private void show(String
type,TransformerException e) {
System.out.println(type + “: “ +
e.getMessage());
if(e.getLocationAsString() != null)
System.out.println(e.getLocationAsString());
}
} |
|
|
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:
|
|
Mar 2008 | Java Jazz Up | 17 |
|
|
|
View All Topics |
All Pages of this Issue |
Pages:
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36,
37,
38,
39,
40,
41,
42,
43,
44,
45,
46,
47,
48,
49,
50,
51,
52,
53 ,
54,
55,
56,
57,
58,
59,
Download PDF |
|
|
|
|
|
|
|
|
|