You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Mark Waschkowski <mw...@gmail.com> on 2007/11/05 19:50:00 UTC

predicate with descendant child

Hi,

I'm trying many different combinations to specify a predicate where
ALL child nodes have some particular value. In other words, I would
like to get all regions that have any children nodes that have a
yearBuilt attribute of 2001.
  ie. documents/regions[//@yearBuilt = '2001']

I tried different combinations of factors but could only make the
predicate apply if I knew what level the child was at:
  ie. documents/regions[*/@yearBuilt = '2001']

but in our case we don't always know the level, hence the need to
apply a predicate using a descendant node. Is this possible? If not,
are there any workarounds?

Thanks,

Mark

Re: predicate with descendant child

Posted by Mark Waschkowski <mw...@gmail.com>.
OK, thanks very much Christoph, thats perfect.

I may create a new jira item as we don't always know what level our
child is at, but your suggestion might be a good workaround for now.

Thanks again!

Mark

On Nov 6, 2007 4:59 AM, Christoph Kiehl <ch...@sulu3000.de> wrote:
> Mark Waschkowski wrote:
>
> > I'm trying many different combinations to specify a predicate where
> > ALL child nodes have some particular value. In other words, I would
> > like to get all regions that have any children nodes that have a
> > yearBuilt attribute of 2001.
> >   ie. documents/regions[//@yearBuilt = '2001']
>
> That's not possible yet. See http://issues.apache.org/jira/browse/JCR-247 last
> comment.
>
> > I tried different combinations of factors but could only make the
> > predicate apply if I knew what level the child was at:
> >   ie. documents/regions[*/@yearBuilt = '2001']
> >
> > but in our case we don't always know the level, hence the need to
> > apply a predicate using a descendant node. Is this possible? If not,
> > are there any workarounds?
>
> If your depth is limited you could do the following:
>
> documents/regions[*/@yearBuilt = '2001' or */*/@yearBuilt = '2001' or
> */*/*/@yearBuilt = '2001']
>
> ... and so on.
>
> Cheers,
> Christoph
>
>

Re: predicate with descendant child

Posted by Christoph Kiehl <ch...@sulu3000.de>.
Mark Waschkowski wrote:

> I'm trying many different combinations to specify a predicate where
> ALL child nodes have some particular value. In other words, I would
> like to get all regions that have any children nodes that have a
> yearBuilt attribute of 2001.
>   ie. documents/regions[//@yearBuilt = '2001']

That's not possible yet. See http://issues.apache.org/jira/browse/JCR-247 last 
comment.

> I tried different combinations of factors but could only make the
> predicate apply if I knew what level the child was at:
>   ie. documents/regions[*/@yearBuilt = '2001']
> 
> but in our case we don't always know the level, hence the need to
> apply a predicate using a descendant node. Is this possible? If not,
> are there any workarounds?

If your depth is limited you could do the following:

documents/regions[*/@yearBuilt = '2001' or */*/@yearBuilt = '2001' or 
*/*/*/@yearBuilt = '2001']

... and so on.

Cheers,
Christoph


Re: predicate with descendant child

Posted by Mark Waschkowski <mw...@gmail.com>.
Hi Dan,

Thanks, but no. You can include "/" inside predicates, I have a
working example of such:

  documents[*/*/@yearBuilt = '2001']

That query gives me the document node for something that is two levels
down that has the yearBuilt attribute set to 2001.

Regards,

Mark


On Nov 5, 2007 2:15 PM, Dan Diephouse <da...@mulesource.com> wrote:
> "/"s can not go inside the brackets. They must always go outside i.e.
> parents//*[@years='10'].
>
> - Dan
>
>
>
> Mark Waschkowski wrote:
> > Hi Dan,
> >
> > Doh, I forgot to mention that I need a particular branch, and realized
> > my example isn't very good. I'll try again.
> >
> > I have the following:
> >
> > /parent1/childJack/years=10
> > /parent2/childJill/years=12
> > /parent3/childJohn/years=35
> > /parent3/childJohn/childSuzy/years=10
> >
> > I need the _adults_ that have children or grandchildren that are 10
> > years old because we are running a special promotion for 10 year olds,
> > and need to notify the adults of it.
> >
> > I would like to write this:
> >
> >   parents[//@years= '10']
> >
> > but no go.
> >
> > Any ideas?
> >
> > Thanks,
> >
> > Mark
> >
> >
> >
> >
> >
> > On Nov 5, 2007 1:51 PM, Dan Diephouse <da...@mulesource.com> wrote:
> >
> >> Mark Waschkowski wrote:
> >>
> >>> Hi,
> >>>
> >>> I'm trying many different combinations to specify a predicate where
> >>> ALL child nodes have some particular value. In other words, I would
> >>> like to get all regions that have any children nodes that have a
> >>> yearBuilt attribute of 2001.
> >>>   ie. documents/regions[//@yearBuilt = '2001']
> >>>
> >>> I tried different combinations of factors but could only make the
> >>> predicate apply if I knew what level the child was at:
> >>>   ie. documents/regions[*/@yearBuilt = '2001']
> >>>
> >>> but in our case we don't always know the level, hence the need to
> >>> apply a predicate using a descendant node. Is this possible? If not,
> >>> are there any workarounds?
> >>>
> >>> Thanks,
> >>>
> >>> Mark
> >>>
> >>>
> >> I think the correct xpath syntax is: documents/regions//*[@yearBuilt =
> >> '2001'].
> >> Cheers,
> >> - Dan
> >>
> >> --
> >> Dan Diephouse
> >> MuleSource
> >> http://mulesource.com | http://netzooid.com/blog
> >>
> >>
> >>
>
>
> --
>
> Dan Diephouse
> MuleSource
> http://mulesource.com | http://netzooid.com/blog
>
>

Re: predicate with descendant child

Posted by Dan Diephouse <da...@mulesource.com>.
"/"s can not go inside the brackets. They must always go outside i.e. 
parents//*[@years='10'].

- Dan


Mark Waschkowski wrote:
> Hi Dan,
>
> Doh, I forgot to mention that I need a particular branch, and realized
> my example isn't very good. I'll try again.
>
> I have the following:
>
> /parent1/childJack/years=10
> /parent2/childJill/years=12
> /parent3/childJohn/years=35
> /parent3/childJohn/childSuzy/years=10
>
> I need the _adults_ that have children or grandchildren that are 10
> years old because we are running a special promotion for 10 year olds,
> and need to notify the adults of it.
>
> I would like to write this:
>
>   parents[//@years= '10']
>
> but no go.
>
> Any ideas?
>
> Thanks,
>
> Mark
>
>
>
>
>
> On Nov 5, 2007 1:51 PM, Dan Diephouse <da...@mulesource.com> wrote:
>   
>> Mark Waschkowski wrote:
>>     
>>> Hi,
>>>
>>> I'm trying many different combinations to specify a predicate where
>>> ALL child nodes have some particular value. In other words, I would
>>> like to get all regions that have any children nodes that have a
>>> yearBuilt attribute of 2001.
>>>   ie. documents/regions[//@yearBuilt = '2001']
>>>
>>> I tried different combinations of factors but could only make the
>>> predicate apply if I knew what level the child was at:
>>>   ie. documents/regions[*/@yearBuilt = '2001']
>>>
>>> but in our case we don't always know the level, hence the need to
>>> apply a predicate using a descendant node. Is this possible? If not,
>>> are there any workarounds?
>>>
>>> Thanks,
>>>
>>> Mark
>>>
>>>       
>> I think the correct xpath syntax is: documents/regions//*[@yearBuilt =
>> '2001'].
>> Cheers,
>> - Dan
>>
>> --
>> Dan Diephouse
>> MuleSource
>> http://mulesource.com | http://netzooid.com/blog
>>
>>
>>     


-- 
Dan Diephouse
MuleSource
http://mulesource.com | http://netzooid.com/blog


Re: predicate with descendant child

Posted by Mark Waschkowski <mw...@gmail.com>.
Hi Dan,

Doh, I forgot to mention that I need a particular branch, and realized
my example isn't very good. I'll try again.

I have the following:

/parent1/childJack/years=10
/parent2/childJill/years=12
/parent3/childJohn/years=35
/parent3/childJohn/childSuzy/years=10

I need the _adults_ that have children or grandchildren that are 10
years old because we are running a special promotion for 10 year olds,
and need to notify the adults of it.

I would like to write this:

  parents[//@years= '10']

but no go.

Any ideas?

Thanks,

Mark





On Nov 5, 2007 1:51 PM, Dan Diephouse <da...@mulesource.com> wrote:
>
> Mark Waschkowski wrote:
> > Hi,
> >
> > I'm trying many different combinations to specify a predicate where
> > ALL child nodes have some particular value. In other words, I would
> > like to get all regions that have any children nodes that have a
> > yearBuilt attribute of 2001.
> >   ie. documents/regions[//@yearBuilt = '2001']
> >
> > I tried different combinations of factors but could only make the
> > predicate apply if I knew what level the child was at:
> >   ie. documents/regions[*/@yearBuilt = '2001']
> >
> > but in our case we don't always know the level, hence the need to
> > apply a predicate using a descendant node. Is this possible? If not,
> > are there any workarounds?
> >
> > Thanks,
> >
> > Mark
> >
> I think the correct xpath syntax is: documents/regions//*[@yearBuilt =
> '2001'].
> Cheers,
> - Dan
>
> --
> Dan Diephouse
> MuleSource
> http://mulesource.com | http://netzooid.com/blog
>
>

Re: predicate with descendant child

Posted by Dan Diephouse <da...@mulesource.com>.
Mark Waschkowski wrote:
> Hi,
>
> I'm trying many different combinations to specify a predicate where
> ALL child nodes have some particular value. In other words, I would
> like to get all regions that have any children nodes that have a
> yearBuilt attribute of 2001.
>   ie. documents/regions[//@yearBuilt = '2001']
>
> I tried different combinations of factors but could only make the
> predicate apply if I knew what level the child was at:
>   ie. documents/regions[*/@yearBuilt = '2001']
>
> but in our case we don't always know the level, hence the need to
> apply a predicate using a descendant node. Is this possible? If not,
> are there any workarounds?
>
> Thanks,
>
> Mark
>   
I think the correct xpath syntax is: documents/regions//*[@yearBuilt = 
'2001'].
Cheers,
- Dan

-- 
Dan Diephouse
MuleSource
http://mulesource.com | http://netzooid.com/blog