xml - When using setParameter with a node-set, it raises exception "Invalid conversion from java.lang.String to node-set" -


i trying transform xml invoking xslt java code. facing issue in passing xml string parameter xslt. causes exception: invalid conversion 'java.lang.string' 'node-set'.

this method invoke xslt:

transformer l_transformer =transformerfactory.newinstance().newtransformer(xslt_file_path); l_transformer.setoutputproperty(outputkeys.encoding, "iso-8859-1"); l_transformer.setparameter("collateraldoc", param_xmlstring);  stringwriter l_writer = new stringwriter(); stringreader l_reader = new stringreader(inputxml);  source l_in = new streamsource(l_reader); result l_out = new streamresult(l_writer);  l_transformer.transform(l_in, l_out); 

after searching solutions tried creating document object param xml string , passed document object setparameter object. got exception:

invalid conversion 'com.sun.org.apache.xerces.internal.dom.deferreddocumentimpl' 'node-set'.

the xslt code processes input xml param , line throws exception: <xsl:variable name="infolist" select="$paramxml/a/b"/>

the param xml need pass param looks this:

<?xml version="1.0" encoding="utf-8" standalone="yes"?> <a>     <b>         <c>             <d>blah</d>             <e>blah</e>         </c>         <f>             <g>blah</g>             <h>blah</h>         </f>     </b> </a> 

please me in resolving issue.

this old question, though think still deserves answer.

the default implementation of jdk uses xalan-j. in 2005, issue raised in jira against xalan 2.7 asking support passing nodes or document objects. in passed 10 years, issue has not yet been resolved, though comments suggest "easy enough do".

the above issue suggests, however, possible pass dom tree. in fact, following appears work:

string doc = "<root>hello world!</root>"; transformer.setparameter("mydoc", new streamsource(new stringreader(doc))); 

if reason cannot switch more capable xslt processor, saxon, may consider relative easy workaround, quote:

one workaround use document function inside stylesheet uri of choosing. install uriresolver on transformer. uriresolver.resolve method should implemented uri , return domsource 1 you've described above.

in addition, 1 override setparameter method register node uriresolver make use orthogonal.

a few alternative workarounds have been given in this answer on over same subject.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -