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.
To use an XSLT parameterCreate an XsltArgumentList object and add the parameter using the AddParam method. Call the parameter from the style sheet. Pass the XsltArgumentList object to the Transform method.
The content model of both elements is the same. The way these elements declare variables is the same. However, the value of the variable declared using <xsl:param> is only a default that can be changed with the <xsl:with-param> element, while the <xsl:variable> value cannot be changed.
In XPath 1.0 (and therefore XSLT 1.0), the container is called the "root node", and the spec uses the term "document element" for the outermost element, though it doesn't play a very significant role, largely because the model supports document nodes having multiple element children.
The <xsl:value-of> element is used to extract the value of a selected node.
(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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With