tags:

views:

57

answers:

2

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.

A: 

If you look at the Document JavaDoc, you can see that it extends Node interface, but not NodeList. Not sure if it will work, but you could try to pass in params.getChildNodes() instead of params.

Neeme Praks
unfortunately I also tried passing the NodeList but no luck
ithkuil
Maybe it is related to this bug? http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5059947
Neeme Praks
Anyway, I would suggest to take the stacktrace of that error and track down in Xalan source code the specific circumstance when this exception is thrown.
Neeme Praks
Yes, before posting here I checked the sources:
ithkuil
java.lang.RuntimeException: Invalid conversion from 'com.sun.org.apache.xerces.internal.dom.DocumentImpl' to 'node-set'. at com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary.runTimeError(BasisLibrary.java:1523) at com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary.runTimeError(BasisLibrary.java:1531) at com.sun.org.apache.xalan.internal.xsltc.runtime.BasisLibrary.referenceToNodeSet(BasisLibrary.java:999)
ithkuil
method "referenceToNodeSet" accepts only "com.sun.org.apache.xalan.internal.xsltc.runtime.Node" instances, which are wrappers to dom nodes. There is a helper used to create those wrappers, in BasisLibrary, which requires a "Translet" instance as a mandatory parameter. The translet instance has to be taken from a protected member of the TransformerImpl instance. Unfortunately the jar is sealed and I get a access exception trying to access that protected getter.
ithkuil
I'm also interested in alternative approaches to my problem. For now I will quickly hack my solution by wrapping the input document together with my parameter class "<package><params>...</params><originaldoc</package>". But I don't really like this kind of hacks. Other ideas would be to create a custom url protocol and use 'select="document('mydummyprotocol:somekey')' and hook 'somekey' to my generated xml. Also this sounds too hackish.
ithkuil
Seems to be a known issue with XALAN compiling processor ( https://issues.apache.org/jira/browse/XALANJ-2057, http://old.nabble.com/How-can-I-pass-a-node-as-parameter-to-translets-for-XSLTC-Processor-td8649149.html).
Neeme Praks
A: 

(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
Neeme Praks
Thank you, I opted for 4
ithkuil
Solution 3 doesn't seem to work when the node to be passed as param comes from a DOM document which is not the document being transformed.
ithkuil