You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Sergey Podatelev <br...@gmail.com> on 2008/11/04 01:45:54 UTC

Select all leafs of a tree w/XPath

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

XPath 2.0 and XQuery 1.0 on JCR

Posted by Ivan Latysh <iv...@gmail.com>.
Jukka Zitting wrote:

> On Mon, Nov 10, 2008 at 4:23 PM, Ivan Latysh <iv...@gmail.com> wrote:
>> 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.
> 
> Would you be interested in contributing that to Jackrabbit or making
> it available elsewhere as open source? I have a number of use cases
> where I'd appreciate more expressive query capabilities even if they
> don't perform as well as native queries.

   The decision to make it open-source has been made, thanks to RefinedData Inc. 
for the contribution. Now I need to talk to Michael Key, if he would like to 
take it on board, since it is Saxon based solution.

   Adapter allows to mix JCR XPath, direct node retrieval by UUID and Saxon 
XPath 2.0 and XQuery 1.0 to achieve optimal performance. We are using it in 
production for reporting.

   I will keep you posted.

-- 
Ivan Latysh
IvanLatysh@gmail.com

Re: XQuery on JCR

Posted by Ivan Latysh <iv...@gmail.com>.
Alessandro Bologna wrote:

> looks very interesting. Can't wait to try, it does certainly give a great
> benefit to be able to use full XQuery. I am curious to see how you
> implemented the navigation. Are you taking any advantage of the lucene
> indexes, or just walking the tree?
Driver uses JCR API only, so no optimization.

Also, as it stated on FAQ page, not all exes are implemented, so some queries will fall.
To complete, I need to finish a List wrapper for NodeIterator, to be able to move the cursor both ways.

-- 
Ivan Latysh
IvanLatysh@gmail.com

Re: XQuery on JCR

Posted by Alessandro Bologna <al...@gmail.com>.
Ivan,

looks very interesting. Can't wait to try, it does certainly give a great
benefit to be able to use full XQuery. I am curious to see how you
implemented the navigation. Are you taking any advantage of the lucene
indexes, or just walking the tree?

Alessandro



On Fri, Jan 30, 2009 at 12:24 PM, Ivan Latysh <iv...@gmail.com> wrote:

> Hello Jukka!
>
>  I have released the first version of JcrDocumentWrapper, that allow to run
> XQuery 1.0 on top of the any JCR repository.
>
>  Project home: http://code.google.com/p/saxon-extensions
>  JcrDocumentWraper wiki:
> http://code.google.com/p/saxon-extensions/wiki/JcrDocumentWraper
>
> --
> Ivan Latysh
> IvanLatysh@gmail.com
>

Re: XQuery on JCR

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Fri, Jan 30, 2009 at 9:41 PM, Ivan Latysh <iv...@gmail.com> wrote:
> Jukka Zitting wrote:
>> Are you set on using LGPL as the license? I'd love to bundle your work
>> as an extra JCR query language in Jackrabbit, but Apache policies [1]
>> prevent us from using LGPL dependencies.
>
> I didn't give it a thought yet.
> I see that Saxon released under "Mozilla Public License 1.0 (MPL)" and since
> my code is based on it, I think I should adhere to it.

MPL 1.0 would be better for us.

BR,

Jukka Zitting

Re: XQuery on JCR

Posted by Ivan Latysh <iv...@gmail.com>.
Jukka Zitting wrote:

> Great stuff, thanks for following up and sharing the code!
> 
> Are you set on using LGPL as the license? I'd love to bundle your work
> as an extra JCR query language in Jackrabbit, but Apache policies [1]
> prevent us from using LGPL dependencies.
I didn't give it a thought yet.
I see that Saxon released under "Mozilla Public License 1.0 (MPL)" and since my code is based on it, I think I should 
adhere to it.

-- 
Ivan Latysh
IvanLatysh@gmail.com

Re: XQuery on JCR

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Fri, Jan 30, 2009 at 6:24 PM, Ivan Latysh <iv...@gmail.com> wrote:
> I have released the first version of JcrDocumentWrapper, that allow to run
> XQuery 1.0 on top of the any JCR repository.

Great stuff, thanks for following up and sharing the code!

Are you set on using LGPL as the license? I'd love to bundle your work
as an extra JCR query language in Jackrabbit, but Apache policies [1]
prevent us from using LGPL dependencies.

[1] http://www.apache.org/legal/resolved.html

BR,

Jukka Zitting

XQuery on JCR

Posted by Ivan Latysh <iv...@gmail.com>.
Hello Jukka!

  I have released the first version of JcrDocumentWrapper, that allow to run XQuery 1.0 on top of the any JCR repository.

  Project home: http://code.google.com/p/saxon-extensions
  JcrDocumentWraper wiki: http://code.google.com/p/saxon-extensions/wiki/JcrDocumentWraper

-- 
Ivan Latysh
IvanLatysh@gmail.com

Re: Select all leafs of a tree w/XPath

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Mon, Nov 10, 2008 at 4:23 PM, Ivan Latysh <iv...@gmail.com> wrote:
> 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.

Would you be interested in contributing that to Jackrabbit or making
it available elsewhere as open source? I have a number of use cases
where I'd appreciate more expressive query capabilities even if they
don't perform as well as native queries.

BR,

Jukka Zitting

Re: Select all leafs of a tree w/XPath

Posted by Sergey Podatelev <br...@gmail.com>.
I see, thanks for the insight, Jukka.

On Thu, Nov 13, 2008 at 5:46 PM, Jukka Zitting <ju...@gmail.com>wrote:

> Hi,
>
> On Mon, Nov 10, 2008 at 4:36 PM, Sergey Podatelev
> <br...@gmail.com> wrote:
> > Thanks to everyone for answers.Ivan, I think I should go with an
> > extra-property method since speed is important for my purposes.
>
> Note that if your only search criteria is "leaf node", then simply
> traversing the tree is the fastest way to find all the nodes you are
> looking for. In any reasonably shaped content model the majority of
> all nodes will be leaves, and search will only be faster than
> traversal when your query targets a notably smaller subset of your
> content tree.
>
> BR,
>
> Jukka Zitting
>



-- 
sp

Re: Select all leafs of a tree w/XPath

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Mon, Nov 10, 2008 at 4:36 PM, Sergey Podatelev
<br...@gmail.com> wrote:
> Thanks to everyone for answers.Ivan, I think I should go with an
> extra-property method since speed is important for my purposes.

Note that if your only search criteria is "leaf node", then simply
traversing the tree is the fastest way to find all the nodes you are
looking for. In any reasonably shaped content model the majority of
all nodes will be leaves, and search will only be faster than
traversal when your query targets a notably smaller subset of your
content tree.

BR,

Jukka Zitting

Re: Select all leafs of a tree w/XPath

Posted by Sergey Podatelev <br...@gmail.com>.
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 <iv...@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

Re: Select all leafs of a tree w/XPath

Posted by Ivan Latysh <iv...@gmail.com>.
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

Re: Select all leafs of a tree w/XPath

Posted by Alexander Klimetschek <ak...@day.com>.
On Sat, Nov 8, 2008 at 11:25 PM, Phil Weighill-Smith
<ph...@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

Re: Select all leafs of a tree w/XPath

Posted by Phil Weighill-Smith <ph...@volantis.com>.
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" <ju...@gmail.com> wrote:

> Hi,
> 
> On Sat, Nov 8, 2008 at 6:53 PM, Sergey Podatelev
> <br...@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

Re: Select all leafs of a tree w/XPath

Posted by Jukka Zitting <ju...@gmail.com>.
Hi,

On Sat, Nov 8, 2008 at 6:53 PM, Sergey Podatelev
<br...@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

Re: Select all leafs of a tree w/XPath

Posted by Sergey Podatelev <br...@gmail.com>.
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