|
|
|
import net.sf.saxon.TransformerFactoryImpl;
|
|
|
|
import javax.xml.transform.Transformer;
|
|
import javax.xml.transform.TransformerException;
|
|
import javax.xml.transform.TransformerFactory;
|
|
import javax.xml.transform.stream.StreamResult;
|
|
import javax.xml.transform.stream.StreamSource;
|
|
import java.io.IOException;
|
|
import java.io.StringReader;
|
|
import java.io.StringWriter;
|
|
import java.net.URISyntaxException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.nio.file.Paths;
|
|
|
|
public class SaxonTestMain {
|
|
|
|
private static final TransformerFactory factory = new TransformerFactoryImpl();
|
|
private static final ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
|
|
|
public static void main(String[] args) {
|
|
try {
|
|
Transformer transformer = factory.newTransformer(new StreamSource(cl.getResourceAsStream("call-named-template.xsl")));
|
|
|
|
StringWriter writer = new StringWriter();
|
|
final Path inputXmlPath = Paths.get(cl.getSystemResource("simple.xml").toURI());
|
|
final String inputXml = new String(Files.readAllBytes(inputXmlPath));
|
|
|
|
transformer.transform(new StreamSource(new StringReader(inputXml)), new StreamResult(writer));
|
|
|
|
System.out.println(writer.toString());
|
|
} catch (final TransformerException | IOException | URISyntaxException exception) {
|
|
System.out.println("Exception caught!");
|
|
}
|
|
}
|
|
}
|