This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes What is the following XSLT program doing ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "What is the following XSLT program doing ?" Watch "What is the following XSLT program doing ?" New topic

What is the following XSLT program doing ?

Mustafa Garhi
Ranch Hand

Joined: Nov 05, 2008
Posts: 111
package xslt;


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;

import org.w3c.dom.Document;

public class DOMXslt
public static void main(String[] args) throws ParserConfigurationException
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.newDocument();

File datafile = new File(args[1]);
document = builder.parse(datafile);
DOMSource source = new DOMSource(document);

TransformerFactory tFactory = TransformerFactory.newInstance();
File stylesheet = new File(args[0]);
StreamSource stylesource = new StreamSource(stylesheet);
Transformer transformer = tFactory.newTransformer(stylesource);

StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
catch (Exception e) {
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 41148
This question has nothing to do with the SCDJWS exam -which this forum is all about- so I'll move it to a more appropriate place.

Ping & DNS - my free Android networking tools app
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

First it takes the (presumably XML) file which is named in the program's second command-line parameter and parses it into a DOM. Then it transforms that DOM, using the (presumably XSLT) file which is named in the program's first command-line parameter, and writes the result to the console.

Since you originally posted the question in a forum about exams, here's a question: some of this processing is unnecessary. What is it and why?
It is sorta covered in the JavaRanch Style Guide.
subject: What is the following XSLT program doing ?
Similar Threads
XML Transformation error
Transformation Problem For Arabic/French Character : HTML to XML
Xalan problem
how to get information from a XML file?
Writing a File and Request Dispatcher Forward