You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Stefan Hagedorn <na...@gmx.de> on 2010/11/11 09:05:21 UTC
XPath: check for property of child node
Hi,
I am not very familiar with XPath and I am trying to build a query that
selects nodes that have a grandchild with a specific name.
My structure is:
<level1>
<level21>
<item name="item1">
<children>
<aaa name="aaa" />
<xxx name="xxx" />
</children>
</item>
<item name="item2">
<children>
<yyy name="yyy" />
<aaa name="aaa" />
</children>
</item>
</level21>
<level22>
<item name="item2">
<children>
<ddd name="ddd" />
<ccc name="ccc" />
</children>
</item>
</level22>
</level1>
What I want to do is to get all item nodes that have e.g. a "xxx"
grandchild.
In my query I do:
/jcr:root/level1//element(item,item-type)[children/xxx/@name='xxx']
It works, but it feels wrong. I would like to leave out the redundant
property/attribute 'name'. But then I will have to check if children/xxx
exists... and I don't know how to do it.
Could anyone please give me a hint?
Thanks in advance!
Stefan
Re: XPath: check for property of child node
Posted by Ard Schrijvers <a....@onehippo.com>.
On Thu, Nov 11, 2010 at 9:05 AM, Stefan Hagedorn <na...@gmx.de> wrote:
> Hi,
>
> I am not very familiar with XPath and I am trying to build a query that
> selects nodes that have a grandchild with a specific name.
>
> My structure is:
>
> <level1>
> <level21>
> <item name="item1">
> <children>
> <aaa name="aaa" />
> <xxx name="xxx" />
> </children>
> </item>
>
> <item name="item2">
> <children>
> <yyy name="yyy" />
> <aaa name="aaa" />
> </children>
> </item>
> </level21>
>
> <level22>
> <item name="item2">
> <children>
> <ddd name="ddd" />
> <ccc name="ccc" />
> </children>
> </item>
> </level22>
> </level1>
>
> What I want to do is to get all item nodes that have e.g. a "xxx"
> grandchild.
>
> In my query I do:
>
> /jcr:root/level1//element(item,item-type)[children/xxx/@name='xxx']
>
> It works, but it feels wrong. I would like to leave out the redundant
> property/attribute 'name'. But then I will have to check if children/xxx
> exists... and I don't know how to do it.
>
> Could anyone please give me a hint?
Don't think it is possible. Normally you would use fn:name() for it
but I don't think it works in a where clause (in the [])
You could try however
Regards Ard
>
> Thanks in advance!
>
> Stefan
>
--
Hippo
Europe • Amsterdam Oosteinde 11 • 1017 WT Amsterdam • +31 (0)20 522 4466
USA • San Francisco 185 H Street Suite B • Petaluma CA 94952-5100
• +1 (707) 773 4646
Canada • Montréal 5369 Boulevard St-Laurent • Montréal QC H2T
1S5 • +1 (514) 316 8966
www.onehippo.com • www.onehippo.org • info@onehippo.com