I spoke too soon re the comment in issue #1 below. It appears that // means (any path under the root of the document where root is defined as the topmost element according to the XmlBeans store - i.e. it is not limited to the node on which you are executing but can go up to that node's parent and grandparent etc until it finds the true root of the tree). On the other hand, $this is bound (statically) to the node you pass in and may therefore not be the root node.
So for me if I navigate to <elem11> below, create an XmlObject from that and then call selectPath("//[EMAIL PROTECTED]/@id]") I get what I think Siegfried originally wanted "all the nodes with an idRef attribute which equals the id attribute in the node I passed in). But make sure you have navigated the XmlCursor to the right place before you create the XmlObject or things can go wrong. Cheers, Lawrence > -----Original Message----- > From: Lawrence Jones > Sent: Thursday, March 30, 2006 2:54 PM > To: user@xmlbeans.apache.org > Subject: RE: selectPath with FilterExpression using $this > > I too have had a go at this, but I too am not an XPath expert. > > First of all make sure you have _all of_ saxon8.jar and saxon8-dom.jar > and xbean_xpath.jar (in addition to the normal xbean.jar and the JSR 173 > jar) on your classpath. Not having saxon8-dom.jar can cause strange > errors. Not having xbean_xpath.jar just means that no XPath will work. > > Other than that I think it might just be that we're not passing in the > right XPath. Siegfried, can you attach an example XML instance document > for which you are expecting this to work? > > Here's the one I tried: > > <elem1 xmlns=\"http://laj.org/test\" > > <elem11 id=\"123\" >text11</elem11> > <elem21 id=\"456\" >text11</elem21> > <elem12 idRef=\"123\" /> > <elem13 idRef=\"456\" /> > <elem14 idRef=\"123\" /> > <elem15 idRef=\"456\" /> > <elem16 idRef=\"123\" /> > <elem17 idRef=\"789\" /> > </elem1> > > And here are the issues I see. > > 1. The element on which you perform the selectPath() call seems to > represent the root as far as the call to selectPath() is concerned. So > if e.g. you passed in only the XmlObject for <elem11> above you should > not expect any of the other elements to be returned regardless of the > XPath passed in. > > 2. But it is likely that the elements with idRef in them are _not_ > children of the element with id in them. Rather it is likely that they > are all members of some larger document element such as <elem1> above. > So to get the selectPath() to even consider them you would need to pass > in the XmlObject for <elem1> (or at least some element that is a root to > all of the results you expect). > > 3. But then the path to the id attribute is no longer $this/@id as that > would only match the _root_ element (<elem1> in this case) having an id > attribute. Exactly what you need to pass in depends on what you want to > do - if you want to find all idRefs that match _any_ id attribute > anywhere in the document then you probably want $this//@id instead. > > 4. I tried the XPath //[EMAIL PROTECTED]//@id] on the complete document > above (i.e. I executed selectPath() on the XmlObject representing > <elem1>) and printed out the list of XmlObjects returned from > selectPath(). I got: > > Number of results = 5 > results[0] = <xml-fragment idRef="123"/> > results[1] = <xml-fragment idRef="456"/> > results[2] = <xml-fragment idRef="123"/> > results[3] = <xml-fragment idRef="456"/> > results[4] = <xml-fragment idRef="123"/> > > which is what I'd expect i.e. I get all the nodes with an idRef that > matches any id attribute somewhere else in the document (and I don't get > those that do not match). Not sure why they are xml-fragment's rather > than proper individual elements with proper QNames but that's a > different issue. > > 5. Note that replacing '$this' with '.' (i.e. XPath = //[EMAIL PROTECTED]//@id) > gave me an empty result set. My guess is that '.' is evaluated > dynamically (i.e. it means the current node that the query has evaluated > to) compared to $this which is bound statically at the beginning to the > root node that you pass in. (With the '.' version of the XPath I think > you are looking for a node which has both an id and an idRef attribute > where the values are the same - which is a slightly different query.) > > I haven't tried this exhaustively - I'm not sure what would happen if > some of the id or idRef attributes were on elements at deeper levels. > But anyway I hope that helps get started. > > Cheers, > > Lawrence > > > -----Original Message----- > > From: Radu Preotiuc-Pietro > > Sent: Thursday, March 30, 2006 1:56 PM > > To: user@xmlbeans.apache.org > > Subject: RE: selectPath with FilterExpression using $this > > > > I was curious to try this myself with the new Saxon 8.6 integration > > (available from the SVN head only, for the moment) and what I found is > > that the path you are suggesting ("//[EMAIL PROTECTED]/@id]") works (no > > exception) but for some reason doesn't return anything. On the other > > hand, "//[EMAIL PROTECTED]'1'" returns the expected result, so on one hand I > am > > wondering if this is maybe a bug in the free version of Saxon and on > the > > other you can use this to workaround the problem by doing > > .selectPath("//[EMAIL PROTECTED]'" + node.getId() + "'"). > > > > If anyone else has other insights into why the original path does not > > work (with more Xpath/Saxon knowledge), I'd also be interested to > know. > > > > Thanks, > > Radu > > > > -----Original Message----- > > From: Cezar Andrei > > Sent: Wednesday, March 29, 2006 3:30 PM > > To: user@xmlbeans.apache.org > > Subject: RE: selectPath with FilterExpression using $this > > > > Hi Siegfried, > > > > I'm not an expert in xpath/xquery but I'm pretty sure that $this > doesn't > > represent the internal current node that is processed by the engine. > > > > So you'll probably want to rewrite the expression to something like > > this: > > xo.selectPath(".//[EMAIL PROTECTED]//@id]"); > > > > As for $this, it's just a variable that is bound to the XmlObject that > > you are calling the selectPath method from. The '$this' construction > is > > not in the latest XPath/Xquery spec so it was deprecated, instead "." > > should be used. > > > > The current XmlObject can be bound to any user specified variable name > > as in the following example: > > > > XmlOptions options = new XmlOptions(); > > options.setXqueryCurrentNodeVar("myVariable"); > > XmlObject[] res = xo.selectPath("declare variable $myVariable > > external; $myVariable//el1", options); > > > > Which is equivalent to: > > > > XmlObject[] res = xo.selectPath(".//el1", options); > > > > And to the following (since in the context of the xpath engine the xo > is > > considered the root): > > > > XmlObject[] res = xo.selectPath("//el1", options); > > > > Since we don't control Saxon, we can't promise that expressions > > confirming to the spec will work. We can only work on making sure we > > make the right calls into Saxon. > > > > Cezar > > > > > > > -----Original Message----- > > > From: Siegfried Baiz [mailto:[EMAIL PROTECTED] > > > Sent: Tuesday, March 14, 2006 12:11 PM > > > To: user@xmlbeans.apache.org > > > Subject: selectPath with FilterExpression using $this > > > > > > Hello, > > > > > > for a given XmlObject xo with an ID-Attribute 'id', I've tried to > > > launch the following xpath-expression: > > > > > > xo.selectPath("//[EMAIL PROTECTED]/@id]") > > > > > > in order to get all nodes (with idRef-Attribute) refering to my node > > xo. > > > > > > Unfortunatlly this expression seems not to work. I always get an > > > java.lang.ArrayIndexOutOfBoundsException from the underlying > > > > > > net.sf.saxon.expr.XPathContextMajor.setLocalVariable(XPathContextMajor.j > > av > > > a:213) > > > > > > At > > > > > > http://xmlbeans.apache.org/docs/2.0.0/guide/conSelectingXMLwithXQueryPat > > hX > > > Path.html > > > I found the following notice: > > > "Notice in the query expression that the variable $this > > represents > > > the current context node (the XmlObject that you are querying > > from). > > > In this example you are querying from the document level > > XmlObject." > > > > > > After reading that sentence I've been thinking, that $this is > somehow > > > similar to "curent()" in XSLT, but maybe a got the meaning wrong. > > > > > > Does anyone know whats the problem here rsp. > > > is there a better way to accomplish the same thing? > > > > > > Thanks a lot, > > > > > > Siggi > > > > > > > > > > > > > --------------------------------------------------------------------- > > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > _______________________________________________________________________ > > Notice: This email message, together with any attachments, may > contain > > information of BEA Systems, Inc., its subsidiaries and > affiliated > > entities, that may be confidential, proprietary, copyrighted > and/or > > legally privileged, and is intended solely for the use of the > individual > > or entity named in this message. If you are not the intended > recipient, > > and have received this message in error, please immediately return > this > > by email and then delete it. > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > _______________________________________________________________________ > > Notice: This email message, together with any attachments, may > contain > > information of BEA Systems, Inc., its subsidiaries and > affiliated > > entities, that may be confidential, proprietary, copyrighted > and/or > > legally privileged, and is intended solely for the use of the > individual > > or entity named in this message. If you are not the intended > recipient, > > and have received this message in error, please immediately return > this > > by email and then delete it. > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > _______________________________________________________________________ > Notice: This email message, together with any attachments, may contain > information of BEA Systems, Inc., its subsidiaries and affiliated > entities, that may be confidential, proprietary, copyrighted and/or > legally privileged, and is intended solely for the use of the individual > or entity named in this message. If you are not the intended recipient, > and have received this message in error, please immediately return this > by email and then delete it. > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] _______________________________________________________________________ Notice: This email message, together with any attachments, may contain information of BEA Systems, Inc., its subsidiaries and affiliated entities, that may be confidential, proprietary, copyrighted and/or legally privileged, and is intended solely for the use of the individual or entity named in this message. If you are not the intended recipient, and have received this message in error, please immediately return this by email and then delete it. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]