| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hello JackRabbit people, I have a problem with selection of all leaf nodes of my tree. The tree consists of nodes of type nt:unstructured named "testnode". I want to select all the nodes that have no children, that is, all the leafs. However, the "//testnode[not(testnode)]" query gives zero results. What is a bit more confusing, is that the "//testnode[testnode]" query returns all the elements of the tree, not just the ones that have at least one child of name "testnode". How should I select leafs? I'm sorry if the question is too dumb, but I'm not closely familiar nor to XPath neither to JackRabbit. -- sp |
|
#2
| |||
| |||
| Seriously, guys, is there an easy way to select leafs or I have to implement a particular property for this? On Tue, Nov 4, 2008 at 3:45 AM, Sergey Podatelev <brightnesslevels@gmail.com > wrote: > Hello JackRabbit people, > > I have a problem with selection of all leaf nodes of my tree. > The tree consists of nodes of type nt:unstructured named "testnode". > > I want to select all the nodes that have no children, that is, all the > leafs. > However, the "//testnode[not(testnode)]" query gives zero results. > > What is a bit more confusing, is that the "//testnode[testnode]" query > returns all the elements of the tree, not just the ones that have at least > one child of name "testnode". > > How should I select leafs? > > I'm sorry if the question is too dumb, but I'm not closely familiar nor to > XPath neither to JackRabbit. > > -- > sp > -- sp |
|
#3
| |||
| |||
| Hi, On Sat, Nov 8, 2008 at 6:53 PM, Sergey Podatelev <brightnesslevels@gmail.com> wrote: > Seriously, guys, is there an easy way to select leafs or I have to implement > a particular property for this? There is no query constraint for selecting leaf nodes. Your idea of using a particular property that you only set on leaf nodes is one way to do this. An alternative would be to use normal tree traversal like this: void visitLeaves(Node node) { NodeIterator nodes = node.getNodes(); if (!nodes.hasNext()) { // ... this is a leaf node, process it ... } else { while (nodes.hasNext()) { visitLeaves(nodes.nextNode()); } } } BR, Jukka Zitting |
|
#4
| |||
| |||
| Are you sure you can't use the XPath expression: //*[count(child::*) = 0] to select the element nodes that have no children (i.e. leaf nodes)? Phil :n. ----- "Jukka Zitting" <jukka.zitting@gmail.com> wrote: > Hi, > > On Sat, Nov 8, 2008 at 6:53 PM, Sergey Podatelev > <brightnesslevels@gmail.com> wrote: > > Seriously, guys, is there an easy way to select leafs or I have to > implement > > a particular property for this? > > There is no query constraint for selecting leaf nodes. > > Your idea of using a particular property that you only set on leaf > nodes is one way to do this. An alternative would be to use normal > tree traversal like this: > > void visitLeaves(Node node) { > NodeIterator nodes = node.getNodes(); > if (!nodes.hasNext()) { > // ... this is a leaf node, process it ... > } else { > while (nodes.hasNext()) { > visitLeaves(nodes.nextNode()); > } > } > } > > BR, > > Jukka Zitting |
|
#5
| |||
| |||
| On Sat, Nov 8, 2008 at 11:25 PM, Phil Weighill-Smith <phil.weighill-smith@volantis.com> wrote: > Are you sure you can't use the XPath expression: > > //*[count(child::*) = 0] > > to select the element nodes that have no children (i.e. leaf nodes)? No, JCR's subset of XPath does not support the count() method. Regards, Alex -- Alexander Klimetschek alexander.klimetschek@day.com |
|
#6
| |||
| |||
| Sergey Podatelev wrote: > Seriously, guys, is there an easy way to select leafs or I have to implement > a particular property for this? Yes there are. I have a Saxon adapter that allow you to run full XPath 2.0 and XQuery 1.0 on JCR. The only caveat is the speed, since adapter uses JCR API only. Let me know if you want to give it a shot. -- Ivan Latysh IvanLatysh@gmail.com |
|
#7
| |||
| |||
| Thanks to everyone for answers.Ivan, I think I should go with an extra-property method since speed is important for my purposes. Thanks for suggestion, though (: On Mon, Nov 10, 2008 at 6:23 PM, Ivan Latysh <ivanlatysh@gmail.com> wrote: > Sergey Podatelev wrote: > > Seriously, guys, is there an easy way to select leafs or I have to >> implement >> a particular property for this? >> > Yes there are. > > I have a Saxon adapter that allow you to run full XPath 2.0 and XQuery 1.0 > on JCR. The only caveat is the speed, since adapter uses JCR API only. > > Let me know if you want to give it a shot. > > -- > Ivan Latysh > IvanLatysh@gmail.com > -- sp |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.