• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

What is the following XSLT program doing ?

 
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
package xslt;

import java.io.File;

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 javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

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();

try
{
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) {
e.printStackTrace();
}
}
}
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 28409
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
reply
    Bookmark Topic Watch Topic
  • New Topic