You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Oliver Wehrens <we...@aei.mpg.de> on 2006/04/07 16:45:49 UTC
Xpath question
Hi,
I have some trouble with xpath queries to jackrabbit.
I want to select the 5th entry and my query would look something like:
q = qm.createQuery("//wiki:entry[5]", Query.XPATH);
qr = q.execute();
NodeIterator it = qr.getNodes();
while (it.hasNext()) {
Node n = it.nextNode();
System.out.println("n.getProperty("wiki:content").getValue().getString());
}
But if I get back the NodeIterator it contains all nodes...where does it go
wrong ?
Variations with //wiki:entry[position()=last()] or things like that also
always give me back the whole list ?
What I try to achieve at the end is to get back the sorted ten last entries
by time (so a order by a property and position()<10, e.g.
//wiki:entry[position()<10] order by @wiki:date descending).
Is that possible (well I guess so but I just don't know how).
Does anybody has an idea?
Thanks, Oliver
--
Oliver Wehrens
+49 170 785 1323
http://wehrens.net/oliver
Re: Xpath question
Posted by Oliver Wehrens <we...@aei.mpg.de>.
Hi,
I just checked it with the latest svn version and it still does not work how
I think it should. I will submit a bug report.
On 10.04.2006 10:52 Uhr, "Marcel Reutegger" <ma...@gmx.net>
wrote:
> Hi Oliver,
>
> Oliver Wehrens wrote:
>> I have some trouble with xpath queries to jackrabbit.
>>
>> I want to select the 5th entry and my query would look something like:
>>
>> q = qm.createQuery("//wiki:entry[5]", Query.XPATH);
>> qr = q.execute();
>> NodeIterator it = qr.getNodes();
>> while (it.hasNext()) {
>> Node n = it.nextNode();
>> System.out.println("n.getProperty("wiki:content").getValue().getString());
>> }
>>
>> But if I get back the NodeIterator it contains all nodes...where does it go
>> wrong ?
>
> this is a bug in the query builder. could you please create a jira
> issue? Thanks.
>
> the problem is with the descendant-or-self axis. if you just use the
> child node axis queries with position predicates work. e.g. something
> like this:
>
> /jcr:root/*/wiki:entry[5]
>
>> Variations with //wiki:entry[position()=last()] or things like that also
>> always give me back the whole list ?
>
> same bug as above.
>
>> What I try to achieve at the end is to get back the sorted ten last entries
>> by time (so a order by a property and position()<10, e.g.
>> //wiki:entry[position()<10] order by @wiki:date descending).
>
> this is actually not yet supported in jackrabbit. so far you can only
> use position predicates with the equals operator.
>
> I'm not sure I understand your use case. If it were possible to execute
> the previous query in jackrabbit you would get the *first* ten
> wiki:entry nodes (in document order) and then sorted by date. I guess
> what you rather want are the 10 latest wiki entries, right?
>
Jupp, make it ascending it the query above ;)
Thanks, Oliver
> regards
> marcel
>
--
Oliver Wehrens
+49 170 785 1323
http://wehrens.net/oliver
Re: Xpath question
Posted by Marcel Reutegger <ma...@gmx.net>.
Hi Oliver,
Oliver Wehrens wrote:
> I have some trouble with xpath queries to jackrabbit.
>
> I want to select the 5th entry and my query would look something like:
>
> q = qm.createQuery("//wiki:entry[5]", Query.XPATH);
> qr = q.execute();
> NodeIterator it = qr.getNodes();
> while (it.hasNext()) {
> Node n = it.nextNode();
> System.out.println("n.getProperty("wiki:content").getValue().getString());
> }
>
> But if I get back the NodeIterator it contains all nodes...where does it go
> wrong ?
this is a bug in the query builder. could you please create a jira
issue? Thanks.
the problem is with the descendant-or-self axis. if you just use the
child node axis queries with position predicates work. e.g. something
like this:
/jcr:root/*/wiki:entry[5]
> Variations with //wiki:entry[position()=last()] or things like that also
> always give me back the whole list ?
same bug as above.
> What I try to achieve at the end is to get back the sorted ten last entries
> by time (so a order by a property and position()<10, e.g.
> //wiki:entry[position()<10] order by @wiki:date descending).
this is actually not yet supported in jackrabbit. so far you can only
use position predicates with the equals operator.
I'm not sure I understand your use case. If it were possible to execute
the previous query in jackrabbit you would get the *first* ten
wiki:entry nodes (in document order) and then sorted by date. I guess
what you rather want are the 10 latest wiki entries, right?
regards
marcel