File: XSLTransform.java

package info (click to toggle)
libjdom0-java 0.9b-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 7,148 kB
  • ctags: 3,104
  • sloc: java: 9,604; xml: 595; makefile: 49; sh: 33; perl: 31
file content (35 lines) | stat: -rw-r--r-- 996 bytes parent folder | download | duplicates (2)
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
import org.jdom.*;
import org.jdom.input.*;
import org.jdom.output.*;
import org.jdom.transform.*;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;

public class XSLTransform {

  public static void main(String[] args) throws Exception {
    if (args.length != 2) {
      System.err.println("Usage: samples.XSLTransform [some.xml] [some.xsl]");
      return;
    }

    String docname = args[0];
    String sheetname = args[1];
    SAXBuilder builder = new SAXBuilder();
    Document doc = builder.build(docname);

    Transformer transformer = TransformerFactory.newInstance()
      .newTransformer(new StreamSource(sheetname));
  
    JDOMSource source = new JDOMSource(doc);
    JDOMResult result = new JDOMResult();
    transformer.transform(source, result);
    Document doc2 = result.getDocument();

    XMLOutputter outp = new XMLOutputter();
    outp.setTextNormalize(true);
    outp.setIndent("  ");
    outp.setNewlines(true);
    outp.output(doc2, System.out);
  }
}