Gary, I put your sample code in, verbatim, with the fix and now I get a "null" TransformerException. Also, do I need to use NodeList or NodeSet? Any ideas? Bart Jenkins, CTO Globeflow SA Cardenal Marcelo Spinola 2, D1, Planta 6 28016 Madrid, Spain telephone: +34 667 65 10 75 -----Original Message----- From: Gary L Peskin [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 26, 2001 8:53 PM To: [EMAIL PROTECTED] Subject: Re: UPDATE: How to correctly process, via Xpath, result-tree-fragments returned by JAVA extensions? More questions... Hmmm. Just noticed that Document myDoc = createDocument(null, "DOCUMENT", null); should be Document myDoc = myDOM.createDocument(null, "DOCUMENT", null); Gary Gary L Peskin wrote: > > Bart -- > > You are returning a String so XalanJ is treating it as just that -- a > String. What you want to return is your NodeSet so that it can be > properly treated like a node-set. > > One example: > > import org.apache.xpath.NodeSet; > import org.apache.xerces.dom.DOMImplementationImpl; > import org.w3c.dom.DOMImplementation; > import org.w3c.dom.Document; > import org.w3c.dom.Node; > import org.w3c.dom.Element; > > public class node1 { > > public static org.apache.xpath.NodeSet getMyXMLStr() > { > > DOMImplementation myDOM = > DOMImplementationImpl.getDOMImplementation(); > Document myDoc = createDocument(null, "DOCUMENT", null); > Node textNode = myDoc.createTextNode("FOO"); > Element elemNode = myDoc.createElementNS(null, "ELEM1A"); > elemNode.appendChild(textNode); > textNode = myDoc.createTextNode("elemlevel"); > Element elemNode2 = myDoc.createElementNS(null, "ELEM1"); > elemNode2.appendChild(textNode); > elemNode2.appendChild(elemNode); > textNode = myDoc.createTextNode("doclevel"); > elemNode = myDoc.getDocumentElement(); > elemNode.appendChild(textNode); > elemNode.appendChild(elemNode2); > > NodeSet retval = new NodeSet(elemNode); > retval.setShouldCacheNodes(true); > return retval; > } > } > > I haven't tested this but you get the idea. If you XML is already in a > file, you may be better off just building a DOM parser and parsing it. > > HTH, > Gary > > "Bart W.Jenkins" wrote: > > > > Gary, > > No problem...here are the files: > > > > Hope you can give me some clues...otherwise I am in trouble as I need to be > > able to retrieve node sets or RTFs from JAVA code... > > > > TIA > > > > Bart Jenkins, CTO > > Globeflow SA > > Cardenal Marcelo Spinola 2, D1, Planta 6 > > 28016 Madrid, Spain > > mobile telephone: +34 667 65 10 75 > > > > -----Original Message----- > > From: Gary L Peskin [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, July 26, 2001 6:14 PM > > To: [EMAIL PROTECTED] > > Subject: Re: UPDATE: How to correctly process, via Xpath, > > result-tree-fragments returned by JAVA extensions? More questions... > > > > Bart -- > > > > In order to understand what you're talking about, please supply the Java > > code for your extension function as well as working XML and XSLT to > > demonstrate the problem. It's very difficult to answer questions like > > this without seeing the whole picture. > > > > When your extension function returns a Node, the extension mechanism > > returns a node-set containing just that single node. > > > > I'm not sure why you say " ... the entire RTF that comes from my JAVA > > call ..." because, when you return a Node, your java program is not > > returning an RTF but a node-set. > > > > Anyway, if you attach the three items that I mentioned, we'll be able to > > look and see what's happening. It would help if you put some comments > > in your XSLT indicating what works and what doesn't. > > > > Thanks, > > Gary > > > > "Bart W.Jenkins" wrote: > > > > > > All, > > > My original post (see below) discussed the problem I was having > > processing > > > (via XPATH) a nodeset returned from a JAVA function call. In the original > > > trials, I was returning a java.lang.String. I since modified my JAVA > > > function to return an org.w3c.dom.Node object and am experiencing the same > > > problem in the XSL processing of this return result. That is, I can place > > > the entire RTF that comes from my JAVA call into the result tree but any > > > applied XPATH statements on it don't seem to do anything. Is it possible > > > that the Xalan processor is seeing "escaped" data and so does not > > recognize > > > the data as a true RTF? > > > > > > Interestingly, if I put this same RTF into the XSL directly, things work > > > fine. That is, if I have: > > > > > > <xsl:variable name="klient"> > > > > > <DOCUMENT>doclevel<ELEM1>elem1level<ELEM1A>FOO</ELEM1A></ELEM1></DOCUMENT> > > > </xsl:variable> > > > > > > ...and I don't use the nodeset extension function and try this... > > > > > > <xsl:value-of select="$klient/DOCUMENT/ELEM1/ELEM1A"/> > > > > > > I get the error: "XSLT Error (javax.xml.transform.TransformerException): > > Can > > > not convert #RTREEFRAG to a NodeList!" > > > (Note: If I use the document() command to pull in this same RTF from a > > file > > > URI, the above select statement works fine which is very convenient) > > > > > > ...however, if I then surround the RTF with the nodeset function like > > this: > > > > > > <xsl:value-of select="xalan:nodeset($klient)/DOCUMENT/ELEM1/ELEM1A"/> > > > > > > ...this will then correctly return the element value "FOO". > > > > > > AS MENTIONED EARLIER, THIS DOES NOT WORK IF THE SAME DATA FOR VARIABLE > > > "klient" IS RETURNED FROM A JAVA FUNCTION CALL. More importantly, this > > does > > > not work either when I return a java.lang.String or a org.w3c.dom.Node > > > object. > > > > > > Is this a bug? Any ideas? ...anyone...? > > > > > > Bart Jenkins, CTO > > > Globeflow SA > > > Cardenal Marcelo Spinola 2, D1, Planta 6 > > > 28016 Madrid, Spain > > > telephone: +34 667 65 10 75 > > > > > > > -----Original Message----- > > > > From: Bart W.Jenkins > > > > Sent: Wednesday, July 25, 2001 7:22 PM > > > > To: '[EMAIL PROTECTED]' > > > > Subject: How to correctly process, via Xpath, result-tree-fragments > > > > returned by JAVA extensions? > > > > > > > > All, > > > > Environment: > > > > OS = Windows 2000 Pro > > > > JAVA=java full version "1.3.1-b24" > > > > Xalan=xalan-j_2_2_D6 > > > > > > > > I have XSL that uses the Xalan JAVA extensions mechanism to make calls > > to > > > > JAVA code to return both simple types (like String) and > > > > result-tree-fragments like the following: > > > > > > > > <DOCUMENT> > > > > <ELEM1> > > > > <ELEM1A>Foo</ELEM1A> > > > > </ELEM1> > > > > </DOCUMENT> > > > > > > > > Problem: Why, when I apply the "xalan:nodeset()" function to my RTF > > that > > > > comes back from my JAVA function can I not use XPATH statements to get > > at > > > > specific elements or attributes in my RTF data? > > > > > > > > Example: Assuming I have a declaration like: > > > > > > > > <?xml version='1.0' encoding='ISO-8859-1' ?> > > > > <xsl:stylesheet version="1.0" > > > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > > > xmlns:Ext="class:com.hg.client" > > > > xmlns:xalan="http://xml.apache.org/xalan" > > > > exclude-result-prefixes="Ext xalan" > > > > > > > > > > > > > I then call into a JAVA function like this: > > > > > > > > <xsl:variable name="myRTF" > > > > select='Ext:myClass.myMethod("someParamData")'/> > > > > > > > > Which does indeed return an RTF which I can see fully if I do a value-of > > > > like: > > > > > > > > <xsl:value-of select="myRTF"/> > > > > > > > > Now, assuming I want the value of "<ELEM1A>" which is "Foo", I assume I > > > > should do this: > > > > > > > > <xsl:value-of select="xalan:nodeset(myRTF)/DOCUMENT/ELEM1/ELEM1A"/> > > > > > > > > But this returns NOTHING and gives NO ERROR. Can someone tell me why? > > > > > > > > Thanks in advance... > > > > > > > > Bart Jenkins, CTO > > > > Globeflow SA > > > > Cardenal Marcelo Spinola 2, D1, Planta 6 > > > > 28016 Madrid, Spain > > > > telephone: +34 667 65 10 75 > > > > > > > > ------------------------------------------------------------------------ > > > > simple.xmlName: simple.xml > > Type: BizTalk Schema (text/xml) > > > > Name: simple.xsl > > simple.xsl Type: BizTalk Schema (text/xml) > > Encoding: quoted-printable > > > > node1.javaName: node1.java > > Type: unspecified type (application/octet-stream)
