Java:将文档转换为现有文档:合并?
我缓存了一个 XSLT 并将其循环应用到多个文档。每个结果都具有相同的格式。
DocumentResult allResults = new DocumentResult();
for (iter = requests.iterator(); iter.hasNext();) {
transformer.transform(new DocumentSource(request), allResults);
}
return allResults;
尽管代码不起作用,但它应该显示我正在尝试尝试的内容:具有相同 ID
值的请求应该合并或附加。
有没有一种方法可以实现这一点而无需手动执行合并?
I cached an XSLT and apply it to several documents in a loop. Each result has the same format.
DocumentResult allResults = new DocumentResult();
for (iter = requests.iterator(); iter.hasNext();) {
transformer.transform(new DocumentSource(request), allResults);
}
return allResults;
Although the code doesn't work it should display what I'm trying to attempt: requests having the same ID
value should be merged or appended otherwise.
Is there a way to implement this without having to perform the merge manually?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议您查看 StreamResult (示例此处和< a href="http://www.ling.helsinki.fi/kit/2004k/ctl257/JavaXSLT/Ch05.html" rel="nofollow">此处)。如果您在开始时创建了适当的 ByteArrayOutputStream,您应该能够从 StreamResult 追加)。
I suggest you look at StreamResult (examples here and here). If you create the appropriate ByteArrayOutputStream at the start you should be able to append from the StreamResult).
我将实现
org.xml.sax.ContentHandler
将所有传入的SAX事件传递到SAXResult
的底层内容处理程序,并跳过所有不必要的事件(startDocument
) code>、endDocument
和startElement
用于根标记。I would implement
org.xml.sax.ContentHandler
passes all the incoming SAX events to the underlying content handler forSAXResult
, and skips all unnecessary events (startDocument
,endDocument
, andstartElement
for root tags.