Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XPath selecting a node with some attribute value equals to some other node's attribute value [closed]

Tags:

xpath

<grand id="grand">   <parent>     <child age="18" id="#not-grand"/>     <child age="20" id="#grand"/> <!-- This is what I want to locate -->   </parent> </grand> 

Can anybody tell me how to express for locating the second child?

This doesn't work...

"/grand/parent/child[@id=concat('#',/grand/@id)]/@age" 

Thank you.


I'm sorry. The expression is OK. I found I got some problems in other area not the expression itself.

like image 690
Jin Kwon Avatar asked May 19 '11 07:05

Jin Kwon


People also ask

Can you use XPath expression used to select the target node and its values?

XPath assertion uses XPath expression to select the target node and its values. It compares the result of an XPath expression to an expected value. XPath is an XML query language for selecting nodes from an XML. Step 1 − After clicking Add Assertion, select Assertion Category – Property Content.

What is the meaning of '/' in XPath?

Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.


2 Answers

This XPath is specific to the code snippet you've provided. To select <child> with id as #grand you can write //child[@id='#grand'].

To get age //child[@id='#grand']/@age

Hope this helps

like image 110
Vaman Kulkarni Avatar answered Sep 26 '22 07:09

Vaman Kulkarni


I think this is what you want:

/grand/parent/child[@id="#grand"] 
like image 38
MarcoS Avatar answered Sep 25 '22 07:09

MarcoS