将xml节点/文档/片段作为参数传递给xslt [英] passing xml nodes/documents/fragments as parameters to xslt

查看:103
本文介绍了将xml节点/文档/片段作为参数传递给xslt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试传递 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);

我得到这个例外:


'从'com.sun.org.apache.xerces.internal.dom.DocumentImpl'到'node-set'的转换无效。'

'Invalid conversion from 'com.sun.org.apache.xerces.internal.dom.DocumentImpl' to 'node-set'.'

我也试过 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编译处理器的已知问题( XALANJ-2057
如何将节点作为参数传递给XSLTC处理器的translet )。

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?


  1. 乱搞URI ,如
    a对如何将节点
    作为参数传递给XSLTC
    处理器的转发邮件
    发布

  2. 而不是
    XALAN编译处理器(XSLTC),
    使用XALAN解释处理器。或支持此类行为的任何其他XSLT处理器。

  3. 使用DTMAxisIterator
    代替,也在如何将节点
    作为参数传递给XSLTC
    处理器
    的translet - 但不确定它是否可行。

  4. 创建一个新的DOM树,结合您的参数DOM和原始的XSLT输入文档

  1. mess around with URIs as outlined in a response to How can I pass a node as parameter to translets for XSLTC Processor post
  2. Instead of XALAN compiling processor (XSLTC), use XALAN interpretive processor. Or any other XSLT processor that supports such behavior.
  3. Use DTMAxisIterator instead, also outlined in a response to How can I pass a node as parameter to translets for XSLTC Processor post - not sure if it will work, though.
  4. Create a new DOM tree, combining your "parameter" DOM and the original XSLT input document

这篇关于将xml节点/文档/片段作为参数传递给xslt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆