javaxalan

passing xml nodes/documents/fragments as parameters to xslt


I tried to pass a w3c.dom.Document, Element and NodeList as parameters to a xslt transform.

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>

I pass the parameter as:

        Document params = createLinksParams(links);
        transformer.setParameter("links", params);

I get this exception:

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

I tried also exslt:node-set(), xalan:nodeset() etc, but it doesn't work.

It seems that internally xalan excepts his own implementation of the Node.

How can I do something similar without incurring in this problem?

I cannot use document($param) because I construct the doc on the fly.


Solution

  • (Posting a new answer, as the previous one did not solve the issue and this new one is radically different from the previous)

    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. 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