Saxon in Java: XSLT for CSV for XML

Mostly continued with this question: XSLT: CSV (or flat file or plain text) in XML

So, I have XSLT from here: http://andrewjwelch.com/code/xslt/csv/csv-to-xml_v2.html

And it converts the CSV file to an XML document. This is done when used with the following command on the command line:

java -jar saxon9he.jar -xsl: csv-to-xml.csv -it: main -o: output.xml

So, now the question becomes: How do I do this in my Java code?

Now I have a code that looks like this:

TransformerFactory transformerFactory = TransformerFactory.newInstance();
StreamSource xsltSource = new StreamSource(new File("location/of/csv-to-xml.xsl"));
Transformer transformer = transformerFactory.newTransformer(xsltSource);
StringWriter stringWriter = new StringWriter();
transformer.transform(documentSource, new StreamResult(stringWriter));
String transformedDocument = stringWriter.toString().trim();

( Transformeris an instance net.sf.saxon.Controller.)

"-it: main", XSLT. , "-s".

Java. / "-it: main"? XSLT, ? XSLT "main"? Transformer.transform(), , , , ?

: , s9api saxon9he.jar, - .

+2
1

JAXP API, XSLT 1.0. XSLT 2.0, , s9api, .

, JAXP, , , , JAXP . , JAXP Transformer net.sf.saxon.Controller, controller.setInitialTemplate(); transform(), null Source.

, , 2.0, TransformerFactory.newInstance(), XSLT-, . net.sf.saxon.TransformerFactoryImpl(), (a) () .

+5

All Articles