0

我希望能够使用单独的 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 列;样式表需要属性:版本”

4

1 回答 1

0

您的 XSL 文件声明中似乎缺少 version 属性。它是从类似的东西开始的吗?

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet 
  version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
于 2012-08-23T19:58:45.513 回答