Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Problem setting part of xpath as parameter

From: "Lillian Djurhuus" <lillian.djurhuus@------->
To:
Date: 6/1/2004 10:48:00 AM
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()[@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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent