java - Saxon-He 9.8 s9Api Transform 函数抛出:net.sf.saxon.trans.XPathException: Failed to read input file exception
问题描述
我试图使用 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();
}
请帮忙。提前致谢。
解决方案
推荐阅读
- api - 通过rest api创建新资源时出现keycloak未知错误
- c# - 从浏览器复制粘贴会锁定 Excel 中未受保护的单元格,该单元格是由 c# 代码使用 EPPlus 创建的
- google-apps-script - 将 Google 表格中的所有数字替换为罗马数字
- r - 如何将数据框中的连续值一起粘贴到新列中
- templates - Azure DevOps 管道模板 - 如何连接参数
- xamarin.forms - Xamarin.Forms 预览器不存在
- c# - NBitcoin 生成重复的比特币地址,对应于等于 1 和 256 的私钥和
- python - 使用 Scrapy 解析本地 XML 文件:DOWNLOAD_TIMEOUT & DOWNLOAD_MAXSIZE 不起作用
- itext7 - 如何减少段落之间的间距 IText 7?
- python - 如何从 numpy 数组中提取居中窗口?