Saxon-He 9.8 s9Api转换函数抛出:net.sf.saxon.trans.XPathException:无法读取输入文件异常

时间:2018-07-22 18:04:26

标签: java transformation saxon

我试图使用Java SaxonHE9-8-0-12J s9api执行XSLT2.0转换。我可以看到正在创建的html文件,但它引发了异常:“ net.sf.saxon.trans.XPathException:无法读取输入文件”。

我想返回最终转换后的XML作为字符串。

以下是我尝试执行的代码:

public String runXSLT(String xsltFile, String strInputXML, boolean cacheEnabled,boolean traceEnabled) throws SaxonApiException, ValidityException, ParsingException {

        Processor proc = new Processor(false);
        XsltCompiler comp = proc.newXsltCompiler();
        XsltExecutable exp = comp.compile(new StreamSource(new File(xsltFile))); //compiled form of stylesheet
        StringReader strRdr = new StringReader(strInputXML);
        StreamSource strSrc = new StreamSource(strRdr);

        DocumentBuilder docBuild = proc.newDocumentBuilder();
        XdmNode source = docBuild.build(strSrc);
        XsltTransformer trans = exp.load();
        trans.setInitialContextNode(source);
        File f = new File("C://Data//transformedXML.html");
        Serializer out = proc.newSerializer();
        out.setOutputProperty(Serializer.Property.METHOD, "html");
        out.setOutputProperty(Serializer.Property.INDENT, "yes");
        out.setOutputFile(f);
        trans.setDestination(out);
        trans.transform();
        return trans.toString();

    }

请帮助。预先感谢。

0 个答案:

没有答案