简体   繁体   English

Xalan XSLT流HTML输出到浏览器

[英]Xalan XSLT Stream HTML output to browser

We are using Xalan XSLT to do XSL transform to generate HTML output ie XML+XSL=HTML. 我们正在使用Xalan XSLT进行XSL转换以生成HTML输出,即XML + XSL = HTML。

Following is the code. 以下是代码。

out=response.getOutputStream();
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer()
transformer.transform(new StreamSource(in), new StreamResult(out));

I do not want for the whole transform to finish before data is displayed on the browser. 我不希望整个转换在数据显示在浏览器上之前完成。 I want the StreamResult that has the HTML output to start sending data to the browser as it does perform xsl transform on individual XML nodes/XSL apply templates so that user gets the impression something is showing on the browser as it is generating because it is possible for the report XML to be big. 我希望具有HTML输出的StreamResult能够开始向浏览器发送数据,因为它确实在各个XML节点上执行了xsl转换/ XSL应用模板,从而使用户对浏览器正在生成的东西有印象,因为这是可能的使报告XML很大。

How do I achive that? 我该如何实现? Does Xalan XSLT support that? Xalan XSLT支持吗? Does any other XSLT parser support it. 是否有其他XSLT解析器支持它。

I would appreciate your advice. 非常感谢您的建议。

The short answer is no, it's not possible to achieve this reliably with Xalan. 简短的答案是“否”,使用Xalan不可能可靠地实现这一目标。

EDIT : However, it might be possible with extensions to Saxon - have a look at them. 编辑 :但是,有可能与撒克逊人的扩展-看看他们。

As for the longer answer, the streaming capabilities of XSLT processors have seen some progress, but the results seem to be too unpredictable yet. 至于更长的答案,XSLT处理器的流功能已经取得了一些进展,但是结果似乎还无法预测。 For example, see this link: http://www.balisage.net/Proceedings/vol5/html/Kay01/BalisageVol5-Kay01.html for a discussion of an attempt to implement Streaming in Saxon. 例如,请参见以下链接: http : //www.balisage.net/Proceedings/vol5/html/Kay01/BalisageVol5-Kay01.html ,以讨论在Saxon中实现流式传输的尝试。

It is assumed that the XSLT 3.0 Recommendation will embrace this question: 假定XSLT 3.0建议书将包含以下问题:

The primary purpose of the changes in this version of the language is to enable transformations to be performed in streaming mode, where neither the source document nor the result document is ever held in memory in its entirety. 对该语言版本进行更改的主要目的是使转换能够以流模式执行,在这种模式下,源文档和结果文档都不会完全保存在内存中。

See http://www.w3.org/TR/xslt-30/ for more information on this. 有关更多信息,请参见http://www.w3.org/TR/xslt-30/ This is only a working draft, though. 不过,这只是一个工作草案。

EDIT : For streaming with Xalan in particular, Michael Kay writes: 编辑 :特别是对于Xalan的流,Michael Kay写道:

Incremental transformation in Xalan doesn't actually stop it building the whole source document as a tree in memory; Xalan中的增量转换实际上并没有阻止它将整个源文档构建为内存中的树。 all it does is to allow the tree to be built in parallel with the transformation process. 它所做的只是允许在转换过程中并行构建树。 If you want a streaming transformation, Saxon-EE is your only practical option. 如果您想进行流媒体转换,那么Saxon-EE是您唯一可行的选择。 [...] [...]

This is taken from Incremental/streaming XSLT transformations? 这取自增量/流XSLT转换? , dating from 2012. Seems like StreamSource is not streaming, really. StreamSource 2012年。似乎StreamSource确实不是流媒体。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM