【发布时间】:2020-07-29 07:59:21
【问题描述】:
我想转换和拆分一个 XML 文档。所以我使用“结果文档”并且它有效。但是当我尝试使用 mavan 启动 XSLT 时,我得到了一个带有 xml 声明的输出 xml 文档。
XSL:
<xsl:result-document method="xml" href="{$filename}_{$Number}.html">
<html>
<head>
<style>
body {
font-family: "Times New Roman", Times, serif;
font-size: 17pt;
line-height: 19pt;
}
</style>
</head>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:result-document>
JAVA:
TransformerFactory factory = TransformerFactory.newInstance();
InputStream inputStream= accessFile(xslpath);
TransformerFactoryImpl f = new net.sf.saxon.TransformerFactoryImpl();
f.setAttribute("http://saxon.sf.net/feature/version-warning", Boolean.FALSE);
f.setAttribute("http://saxon.sf.net/feature/linenumbering", Boolean.TRUE);
StreamSource schemaSource = new StreamSource(inputStream);
Transformer t = f.newTransformer(schemaSource);
StreamSource src = new StreamSource(new FileInputStream(inputpath));
StreamResult res = new StreamResult(new ByteArrayOutputStream());
t.transform(src, res);
String a= res.getOutputStream().toString();
怎么了?
提前致谢
【问题讨论】:
-
目前尚不清楚在哪种情况下您会得到想要的结果,以及由于您没有提供最少但完整的 XML 输入示例、XSLT 代码、您想要的结果以及与您想要的结果相比,它看起来如何得到。您是否希望任何
xsl:result-documents 出现在StreamResultres或Java 代码中的其他变量中?还是在磁盘上作为文件?