Saxon in Java: XSLT for CSV to XML

nebreg

New Member
Mostly continued from this question: http://stackoverflow.com/questions/10655762/xslt-csv-or-flat-file-or-plain-text-to-xmlAnd it converts a CSV file to an XML document. It does this when used with the following command on the command line:\[quote\] java -jar saxon9he.jar -xsl:csv-to-xml.csv -it:main -o:output.xml\[/quote\]So now the question becomes: How do I do I do this in my Java code?Right now I have code that looks like this:\[code\]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();\[/code\](The \[code\]Transformer\[/code\] is an instance of \[code\]net.sf.saxon.Controller\[/code\].)The trick on the command line is to specify "-it:main" to point right at the named template in the XSLT. This means you don't have to provide the source file with the "-s" flag.The problem starts again on the Java side. Where/how would I specify this "-it:main"? Wouldn't doing so break other XSLT's that don't need that specified? Would I have to name every template in every XSLT file "main?" Given the method signature of Transformer.transform(), I have to specify the source file, so doesn't that defeat all the progress I've made in figuring this thing out?Edit: I found the s9api hidden inside the saxon9he.jar, if anyone is looking for it.
 
Back
Top