I have created a child process in node.js and gave it an executable jar file location.
var fs = require('fs');
var exec = require('child_process').exec;
var child = exec('java -jar C:/Users/njaiswal/Desktop/Executable/Saxon.jar',
function (error, stdout, stderr){
fs.writeFile('output.html', +stdout);
if(error !== null){
console.log("Error -> "+error);
}
});
module.exports = child;
This is my Saxon.java which I have converted it into jar file. As you can see, this java program takes result1.xml file and defaultfrontend.xslt stylesheet and convert it into an html web page (output.html).
import java.io.File;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class Saxon {
/**
* Simple transformation method.
*
* @param sourcePath
* - Absolute path to source xml file.
* @param xsltPath
* - Absolute path to xslt file.
* @param resultDir
* - Directory where you want to put resulting files.
*/
public static void simpleTransform(String sourcePath, String xsltPath,
String resultDir) {
TransformerFactory tFactory = TransformerFactory.newInstance();
try {
Transformer transformer = tFactory
.newTransformer(new StreamSource(new File(xsltPath)));
transformer.transform(new StreamSource(new File(sourcePath)),
new StreamResult(new File(resultDir)));
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Set saxon as transformer.
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
simpleTransform("result1.xml", "defaultfrontend.xslt", "output.html");
}
}
So this program converts xml into html using xslt stylesheet. I want to get my output(in html) in node.js.
But when I try to run my javascript, I am not getting any output. The output looks like this: https://i.stack.imgur.com/S0xg0.png