You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Michael Singer <ja...@it-specialist.at> on 2006/02/02 15:25:56 UTC

xpath

Hi,

I want to build an xpath query which returns all nodes of a particular
(well known) type where the property "value" of child node "name" has
the value "test".

e.g.:

node-a (of type level1)
    node name (of type language)
        property id="de"
        property value="deutsch"
    node name[2] (of type language)
        property id="en"
        property value="english"
node-b (of type level1)
    node name (of type language)
        property id="de"
        property value="deutsch"
    node name[2] (of type language)
        property id="en"
        property value="english"
node-c (of type level1)
    node name (of type language)
        property id="de"
        property value="anderes"
    node name[2] (of type language)
        property id="en"
        property value="other"

I want to have all nodes of type "level1" where the property "value" of
all child nodes "name" (or all child nodes of type "language") equals
"english". So the expected result with the above structure is:

node-a
node-b

Can somebody suggest an xpath query for that?

-- 
kind regards

Michael

Re: xpath

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

On 2/2/06, Jukka Zitting <ju...@gmail.com> wrote:
>     //element(*,'type')[name/@value='test']

Sorry, I always forget that the type name in element() does not need
quoting. Here's a correct version of the query:

    //element(*,type)[name/@value='test']

Of course this won't work either in Jackrabbit.

BR,

Jukka Zitting

--
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftmanship, JCR consulting, and Java development

Re: xpath

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

On 2/2/06, Michael Singer <ja...@it-specialist.at> wrote:
> I want to build an xpath query which returns all nodes of a particular
> (well known) type where the property "value" of child node "name" has
> the value "test".

The normal XPath query for this would be something like this:

    //element(*,'type')[name/@value='test']

Unfortunately Jackrabbit doesn't support the child node axis in XPath
predicates (see JCR-247), which means that the above query will not
work.

I can't think of a simple workaround to this issue, so my solution
would be to run a query like //*[@value='test'] and post-process the
results with:

    while (iterator.hasNext()) {
        Node node = (Node) iterator.next();
        Node parent = node.getParent();
        if (parent.getPrimaryNodeType().isNodeType("type")) {
            // process parent node
        }
    }

Another solution would be to redesign the node type structure to match
the limitations of the Jackrabbit query capabilities.

BR,

Jukka Zitting

--
Yukatan - http://yukatan.fi/ - info@yukatan.fi
Software craftmanship, JCR consulting, and Java development