Hi all!
Im having a problem with a parameter set from java to a xsl document.
It used to work. But moving from version Xalan Java 1 to Xalan Java 2 it
doesnt anymore.
I have the following Java testcode, that makes the transformation:
try {
String fileName =
"C:\\javadevelopSource\\Danskkaution8.1\\src\\web\\WEB-INF\\classes\\xsls\\topmenu.xsl";
String xmlfile=
"C:\\javadevelopSource\\Danskkaution8.1\\src\\web\\WEB-INF\\classes\\uniklink\\uniklink.xml";
File file = new File(fileName);
File file2 = new File(xmlfile);
StreamSource source = new StreamSource(file);
TransformerFactory f = TransformerFactory.newInstance();
Transformer trans = f.newTransformer(source);
StringWriter out=new StringWriter();
StreamResult result=new StreamResult(out);
trans.setParameter("xpath", "Root[1]/Niv0[1]/Niv1[1]/");
trans.transform(new StreamSource(file2),result);
System.out.println(out);
} catch (Exception e) {
fail("Error on transforming xml with xsl "+e);
}
in the xsl file I have the following:
.
.
.
<xsl:param name="xpath" />
.
.
<xsl:for-each select="$xpath/child::node()[(_at_)Visible='true'].......more
conditions...
The error I get is:
org.apache.xpath.XPathException: Can not convert #STRING to a NodeList!
Somehow it cant put the value of the xpath parameter in the select
statement and interpret it as a nodelist.
I can output the value in the xsl by:
<xsl:value-of select="$xpath"/>
giving the String:
Root[1]/Niv0[1]/Niv1[1]/
In xalanJ version 1 I put the value set in java in qoutes (')
trans.setParameter("xpath", " 'Root[1]/Niv0[1]/Niv1[1]/' ");
and it worked fine.
This gives an error in version 2 and I read in the documentation, that '
no longer was necessary.
Anyway it still doesnt work!
Can anyone give me an explanation and solution?
Thanks in advance!
Lillian Djurhuus