php xpath find node with descendant having specific attribute -


i have multi level <ul><li> menu structure. trying top level li has descendant li class of "current-menu-line".

my html

<ul id="menu1" class="nav">   <li class="menu-item dorment-menu-item"><a href="http://localhost/index.html">welcome</a></li>   <li class="menu-item dorment-menu-item"><a href="http://localhost/evidence.html">evidence</a></li>   <li class="menu-item dorment-menu-item"><a href="http://localhost/network.html">network</a></li>   <li class="menu-item dorment-menu-item"><a href="http://localhost/multi-page-pc-22.html">multi page</a>     <ul class="subnav">       <li class="menu-item current-menu-line"><a href="http://localhost/new-page-1-pg-47.html">page 1</a></li>     </ul>   </li> </ul> 

i have tried number of xpath queries topmost <li> has descendant no success

$query = '//li[contains(@class, "current-menu-line")]'; // 1 works ... makes sure li.current-menu-line can found $query = '/ul/li[li[contains(@class, "current-menu-line")]]'; // returns 0 rows $query = '/ul/li[//li[contains(@class, "current-menu-line")]]'; // returns 0 rows $query = '/ul/li[descendant::li[contains(@class, "current-menu-line")]]'; // returns 0 rows 

// added after examining "select elements has descendent using xpath"

$query = '/ul/li[.//li[contains(@class, "current-menu-line")]]' ; // returns 0 nodes $query = "/ul/li[descendant::li[@class, 'current-menu-line')]]"; // invalid query 

is able tell me correct query correct li ?

cheers

this selection should fit description:

 /ul/li[.//li[contains(@class, 'current-menu-line')]] 

i see tried , did not return nodes you, suspect there might difference in xml-snipped provided actual xml use. verified xpath using an online xpath evaluator , returns correct result if nested structure more 2 levels below.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -