我有一个xml结构:
<Pages> <!--This is the root node-->
<Home>
<url>...</url>
<menu>
<item>Help</item>
<item>About</item>
<item>Contact</item>
</menu>
</Home>
<Help>
<url>...</url>
<menu> <!--i need to select this if its parent(Help) is listed in Home/menu/item above-->
<item>Business Help</item>
<item>Web Help</item>
<item>Tour Help</item>
</menu>
</Help>
<About>
<url>...</url>
<menu> <!--And Or select this if its parent(About) is listed in Home/menu/item above-->
<item>About us</item>
<item>About our food</item>
</menu>
</About>
<Contact>
<url>...</url>
<menu> <!--And Or select this if its listed in Home/menu/item above-->
...
and so on...
...
</menu>
</Contact>
</Pages>
&#13;
$PageName = 'Home';
"./*/*[name() = 'menu' and ../../$this->PageName/menu/item/. = name(..)]";
and
"./*[name() = (following-sibling::$this->PageName | preceding-sibling::$this->PageName)/menu/*]/menu";
&#13;
在任何一种情况下,我在var_dump()之后得到的结果是:
'menu' =>
array (size=1)
'item' =>
array (size=3)
0 => string 'Business Help' (length=13)
1 => string 'Web Help' (length=8)
2 => string 'Tour Help' (length=9)
//instead of something like :
'menu' =>
array (size=2)
'item' =>
array (size=3)
0 => string 'Business Help' (length=13)
1 => string 'Web Help' (length=8)
2 => string 'Tour Help' (length=9)
'item' =>
array (size=2)
0 => string 'About us' (length=8)
1 => string 'About our food' (length=14)
...
&#13;