473,320 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XPath abbreviated form

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
3 1839
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of...
2
by: Felicity | last post by:
Hello, Using the following XML file, I would like to be able to filter using an XPath to the nodes where Menu = Yes and Form Name = frmMainMenu <?xml version="1.0" standalone="yes"?>...
1
by: Brad Hehe | last post by:
I am attempting to use XPath to query for a specific node in the sample XML I've provided below. I'm unsure of the exact XPath syntax, but I believe I need the following query to get the proper...
13
by: David Thielen | last post by:
XPathNavigator nav = MyCreateNav(); // InnerXml == "software" nav.SelectSingleNode"."); The select returns an exception: + $exception {"'.' has an invalid token."} System.Exception...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
3
by: werD | last post by:
Hello I have an xml document that im currently using a forward only .net repeater on and using some xpath queries to display the data The xml is quite simple <?xml version="1.0"...
3
by: mike | last post by:
Hello, I am new to XPATH and am having a hard time selecting some nodes. I want to select all the record nodes where Status = 'Unprocessed' or 'Queued' (that part I can get) but additionally I...
1
by: bruce | last post by:
Hi. Got a test web page, that basically has two "<html" tags in it. Examining the page via Firefox/Dom Inspector, I can create a test xpath query "/html/body/form" which gets the target form for...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.