Select element that resides between two elements

Viewed 41

Thought this was going to be an easy query... my limited XPath knowledge certainly does not help and I'm probably complicating things.

Trying to locate any EFFECT tags that reside between two SUBTASK tags.

<TOPIC>
 <TITLE/>
 <EFFECT/>            
 <SUBTASK>
 </SUBTASK>
 <EFFECT/>
 <SUBTASK>
 </SUBTASK>
</TOPIC>

Here's a false positive example:

<TC>
 <TCBODY>
  <TASK>
   <EFFECT/>
   <TITLE/>
   <TOPIC>
    <TITLE/>
    <EFFECT/>
    <SUBTASK>
     <EFFECT/>
    </SUBTASK>
   </TOPIC>
  </TASK>
 </TCBODY>
</TC>

UPDATE: The above question has been answered and the following expression worked:

//EFFECT[preceding-sibling::SUBTASK and following-sibling::SUBTASK] 

Now trying to locate any EFFECT tag where the preceding-sibling and following-sibling are the same - no matter what the element name is.

Tried this expression but its returning too many false positives:

//EFFECT[preceding-sibling::*[name()] = following-sibling::*[name()]

Any help would be greatly appreciated!! Thanks

0 Answers
Related