You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Neil <nc...@hotmail.com> on 2011/02/15 15:04:44 UTC

XPath Query Help

Hello Everyone,

I have some 'ths:file' nodes with the names 2800069512 and 2800069903. 

The path to these nodes are the following:

/jcr:root/permanent/280/006/951/2/

/jcr:root/permanent/280/006/990/3/

What I would like to do is get all ths:file nodes under
/jcr:root/permanent/280/006/9**. I would expect to get back both 2800069512
and 2800069903.

I have tried the following:

/jcr:root/permanent/_x0032_80/_x0030_06/_x0039_//element(*,ths:file)order by
jcr:score()

/jcr:root/permanent/_x0032_80/_x0030_06/_x0039_**//element(*,ths:file)order
by jcr:score()

/jcr:root/permanent/_x0032_80/_x0030_06/_x0039_**/*//element(*,ths:file)order
by jcr:score()

The query doesn't fail, it just returns nothing. The thing I am not sure
about is the wildcards in the path.I cannot seem to find any good examples
of this and I am relatively new to xpath.

If I run:

/jcr:root/permanent/_x0032_80/_x0030_06//element(*,ths:file)order by
jcr:score()

I get the files I am looking along with 120 others.

Any help would  be greatly appreciated,
           Neil
-- 
View this message in context: http://jackrabbit.510166.n4.nabble.com/XPath-Query-Help-tp3306803p3306803.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: XPath Query Help

Posted by Justin Edelson <ju...@justinedelson.com>.
AFAIK, XPath doesn't support this kind of glob expression inside a path segment.

But even if it did, you're probably better off using node.getNodes("9*") to get all the nodes starting with '9'

Justin

On Feb 15, 2011, at 9:04 AM, Neil <nc...@hotmail.com> wrote:

> 
> Hello Everyone,
> 
> I have some 'ths:file' nodes with the names 2800069512 and 2800069903. 
> 
> The path to these nodes are the following:
> 
> /jcr:root/permanent/280/006/951/2/
> 
> /jcr:root/permanent/280/006/990/3/
> 
> What I would like to do is get all ths:file nodes under
> /jcr:root/permanent/280/006/9**. I would expect to get back both 2800069512
> and 2800069903.
> 
> I have tried the following:
> 
> /jcr:root/permanent/_x0032_80/_x0030_06/_x0039_//element(*,ths:file)order by
> jcr:score()
> 
> /jcr:root/permanent/_x0032_80/_x0030_06/_x0039_**//element(*,ths:file)order
> by jcr:score()
> 
> /jcr:root/permanent/_x0032_80/_x0030_06/_x0039_**/*//element(*,ths:file)order
> by jcr:score()
> 
> The query doesn't fail, it just returns nothing. The thing I am not sure
> about is the wildcards in the path.I cannot seem to find any good examples
> of this and I am relatively new to xpath.
> 
> If I run:
> 
> /jcr:root/permanent/_x0032_80/_x0030_06//element(*,ths:file)order by
> jcr:score()
> 
> I get the files I am looking along with 120 others.
> 
> Any help would  be greatly appreciated,
>           Neil
> -- 
> View this message in context: http://jackrabbit.510166.n4.nabble.com/XPath-Query-Help-tp3306803p3306803.html
> Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: XPath Query Help

Posted by Neil <nc...@hotmail.com>.
Alex,

      Thanks a bunch! I didnt know we could use jcr:like with fn:name() now
and on top of that it would have never occurred to me to put the
'*[jcr:like(fn:name(),"9__")]' inside the path structure. 


      This worked great.


Neil
-- 
View this message in context: http://jackrabbit.510166.n4.nabble.com/XPath-Query-Help-tp3306804p3306891.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.

Re: XPath Query Help

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 15.02.11 15:04, "Neil" <nc...@hotmail.com> wrote:
>What I would like to do is get all ths:file nodes under
>/jcr:root/permanent/280/006/9**

In the newest Jackrabbit 2.2 you should be able to use wildcards on node
names, previously this was simply not possible. Use jcr:like (where "%" is
the wildcard for any number of chars and "_" is a single char wildcard)
together with fn:name():

/jcr:root/permanent/_x0032_80/_x0030_06/*[jcr:like(fn:name(),
"9__")]//element(*,ths:file) order by jcr:score()


BTW  the "*" in your path step examples means any node (at that level),
but you can't mix characters and wildcards in normal xpath location steps
to match node names.

Regards,
Alex

-- 
Alexander Klimetschek
Developer // Adobe (Day) // Berlin - Basel