I have a multi level <ul><li> menu structure. I am trying to get the top level LI that has a descendant LI with a 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 a number of xPath queries to get the topmost <li> that has the descendant with no success
$query = '//li[contains(@class, "current-menu-line")]'; // this one works ... makes sure LI.current-menu-line can be 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 which has certain 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 someone able to tell me the correct query to get the correct LI ?
Cheers
//li[contains(@class, 'current-menu-line')]/../..