I'm trying to translate this command line code (which takes a .csv file and converts to xml through an xslt file and this works) to Java code: java -jar saxon9he.jar -xsl:"csv2xml.xslt" flatfile=input.csv -s:dummy.xml > output.txt
//Java Code using Saxon-HE 9.5: public static void transformFileUsingStyleSheet(String csvFile, String xslID) throws TransformerException {
// Create a transform factory instance.
TransformerFactory tfactory = TransformerFactory.newInstance();
// Create a transformer for the stylesheet.
Transformer transformer =
tfactory.newTransformer(new StreamSource(xslID));
// Transform the source XML to System.out.
transformer.transform(new StreamSource(csvFile),
new StreamResult(new File("ConvertedCSV2XML.xml")));
}
But I'm getting this error when calling the above java method: SXXP0003: Error reported by XML parser: Content is not allowed in prolog like this: transformFileUsingStyleSheet("input.csv","csv2xml.xslt.xslt");
dummy.xml
) and the CSV as anxsl:param
. You can read the CSV for processing withunparsed-text()
. (That's what appears to be happening anyway based on the command line.) – Daniel Haley