从 Mavan 进行 XSLT 转换以使用结果文档创建多个文档的问题

Problem with XSLT transformation from Mavan to create multiple documents with result-document

我想转换和拆分 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(); 

怎么了?

提前致谢

作为一个大胆的猜测,我假设您在 xsl:result-document method="xml" href="{$filename}_{$Number}.html" 中遇到了相对 URI 的错误;当您在 ByteArrayOutputStream 上转换为 StreamResult 时,我认为处理器没有绝对的基本输出 URI 来解析在 href 属性中构造的相对 URI。

假设 XSLT 2 处理器是 Saxon 9 或 10 的某个版本,它可能取决于使用 JAXP 时如何设置基本输出 URI 的确切版本 Transformer API;我认为对于 Saxon 10,您可以使用 e.h。 ((TransformerImpl)t).getUnderlyingXsltTransformer().setBaseOutputURI("file:///dir/subfolder/subsubfolder/"); 写入某个文件夹。

如果你换成萨克森自己的API,你处理Processors9apihttp://saxonica.com/html/documentation/using-xsl/embedding/s9api-transformation.html),这些事情就更简单直接了,XsltCompilerXsltExecutableXsltTransformerXslt30Transformer.