By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,359 Members | 1,495 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,359 IT Pros & Developers. It's quick & easy.

XPath abbreviated form

P: n/a
What is the the syntax of the abbreviated form of the following XPath
query?

child::a/descendant::b[descendant::text()="foo"]

I try with

a//b[//text()="foo"]

but I get two nodes selected instead of one in

<?xml version="1.0"?>
<a>
<x>
<b>
<u>foo</u>
<v>bar</v>
</b>
</x>
<y>
<b>
<w>bar</w>
</b>
</y>
</a>

I am using Jaxen 1.1.1.
Klem fra Nils

Jun 25 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Jun 25, 7:29 am, nils.grim...@gmail.com wrote:
What is the the syntax of the abbreviated form of the following XPath
query?

child::a/descendant::b[descendant::text()="foo"]

I try with

a//b[//text()="foo"]

but I get two nodes selected instead of one in

<?xml version="1.0"?>
<a>
<x>
<b>
<u>foo</u>
<v>bar</v>
</b>
</x>
<y>
<b>
<w>bar</w>
</b>
</y>
</a>

I am using Jaxen 1.1.1.

Klem fra Nils
The expression below should work and return only one node

a//b[.//text() = "foo"]

This provides only one node by prefixing '//' with '.' (self) in the
predicate.

Phil Fearon
http://www.sketchpath.com


Jun 25 '07 #2

P: n/a
In article <11*********************@m36g2000hse.googlegroups. com>,
<ni**********@gmail.comwrote:
>What is the the syntax of the abbreviated form of the following XPath
query?

child::a/descendant::b[descendant::text()="foo"]

I try with

a//b[//text()="foo"]
the "//text()" in the predicate means and text descendants of the root
node. To find descendants of the context node, you need ".//text()".

Incidentally, "//" isn't exactly the same as "descendant". In
particular, "//*[1]" is not the same as "/descendant::*[1]", but it
doesn't make any difference in this case.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Jun 25 '07 #3

P: n/a
ni**********@gmail.com a écrit :
What is the the syntax of the abbreviated form of the following XPath
query?

child::a/descendant::b[descendant::text()="foo"]

I try with

a//b[//text()="foo"]

but I get two nodes selected instead of one in
// is short for /descendant-or-self::node()/

a//b[//text()="foo"]
means
a//b[/descendant-or-self::node()/="foo"]
it starts from the root

a//b[.//text()="foo"]
means
a//b[./descendant-or-self::node()/="foo"]
it doesn't start from the root
Jun 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.