问题描述
我尝试传递 w3c.dom.Document
,元素
和 NodeList
作为xslt转换的参数。
I tried to pass a w3c.dom.Document
, Element
and NodeList
as parameters to a xslt transform.
我希望能够在xslt中处理它:
I want to be able to process it within the xslt:
<xsl:param name="links" />
<xsl:template match="/">
<record>
<xsl:for-each select="$links/*">
<test />
</xsl:for-each>
</record>
</xsl:template>
我将参数传递为:
Document params = createLinksParams(links);
transformer.setParameter("links", params);
我得到这个例外:
我也试过 exslt:node-set()
, xalan:nodeset()
等等,但它不起作用。
I tried also exslt:node-set()
, xalan:nodeset()
etc, but it doesn't work.
似乎内部xalan除了他自己的Node实现。
It seems that internally xalan excepts his own implementation of the Node.
如何在不引发此问题的情况下做类似的事情?
How can I do something similar without incurring in this problem?
我无法使用文档($ param)
,因为我会动态构建文档。
I cannot use document($param)
because I construct the doc on the fly.
推荐答案
(发布一个新答案,因为前一个答案没有解决问题,这个新答案与前一个完全不同)
似乎是XALAN编译处理器的已知问题(,
)。
Seems to be a known issue with XALAN compiling processor ( XALANJ-2057,How can I pass a node as parameter to translets for XSLTC Processor).
那么,有哪些替代方案?
So, what are the alternatives?
- 乱搞URI ,如
a对发布 - 而不是
XALAN编译处理器(XSLTC),
使用XALAN解释处理器。或支持此类行为的任何其他XSLT处理器。 - 使用DTMAxisIterator
代替,也在的translet - 但不确定它是否可行。 - 创建一个新的DOM树,结合您的参数DOM和原始的XSLT输入文档
- mess around with URIs as outlined ina response to How can I pass a nodeas parameter to translets for XSLTCProcessor post
- Instead ofXALAN compiling processor (XSLTC),use XALAN interpretive processor. Or any other XSLT processor that supports such behavior.
- Use DTMAxisIteratorinstead, also outlined in a response to How can I pass a nodeas parameter to translets for XSLTCProcessor post - not sure if it will work, though.
- Create a new DOM tree, combining your "parameter" DOM and the original XSLT input document
这篇关于将xml节点/文档/片段作为参数传递给xslt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!