Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing xml nodes/documents/fragments as parameters to xslt

Tags:

java

xalan

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.

like image 706
mkm Avatar asked Sep 24 '10 16:09

mkm


People also ask

How do you use parameters in XSLT?

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.

What is difference between Param and variable in XSLT?

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.

What is root node in XSLT?

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.

Which symbol is used to get the element value in XSLT?

The <xsl:value-of> element is used to extract the value of a selected node.


1 Answers

(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
like image 79
Neeme Praks Avatar answered Oct 06 '22 13:10

Neeme Praks