我希望能够使用单独的main方法将输入文件和输出文件传递到此程序中。我的意图是通过GUI访问它。
public class SimpleTransform {
public static void main(String[] args) throws TransformerException, TransformerConfigurationException, FileNotFoundException, IOException {
// Use the static TransformerFactory.newInstance() method to instantiate
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource("demiprocess.xsl"));
transformer.transform(new StreamSource("Anzer.xml"), new StreamResult(new FileOutputStream("lee.xml")));
System.out.println("*The result is in birds.out ***");
}
}
这是我尝试的但是我一直收到错误:
public class Simple {
private String xmlFile ;
private String xslFile;
private String outputFile;
/**
* Constructor for objects of class Simple
*/
public Simple(String xmlFile, String xslFile,String outputFile) {
this.xmlFile = xmlFile;
this.xslFile = xslFile;
this.outputFile= outputFile;
}
public String SimpleTransform() throws TransformerException,TransformerConfigurationException,FileNotFoundException, IOException {
String mystring = "";
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile));
transformer.transform(new StreamSource(xmlFile), new StreamResult(new FileOutputStream(outputFile)));
return mystring = "***The result is in birds.out *****";
}
}
我收到此错误“file:/// C:/Users/Abiodun/Desktop/New%20system/new%20system/demiprocess.xsl;第1行;第10列;样式表需要属性:版本”
答案 0 :(得分:0)
您似乎缺少XSL文件声明中的version属性。它是从类似的东西开始的吗?
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">