xml - XPath - find lowest elements with specific attribute values -


how can list of elements fit condition, don't have decedents fit same condition (i.e. lowest elements in hierarchy fit condition)?

for instance, consider following xml:

<root>   <parent1 mycond='true'>     <child1 mycond='false'>       ...     </child1>     <child2 mycond='true'>       ...     </child2>     <child3 mycond='false'>       ...     </child3>   </parent1>   <parent2 mycond='false'>     <child1 mycond='false'>       ...     </child1>     <child2 mycond='true'>       ...     </child2>   </parent2>   <parent3 mycond='true'>     <child1 mycond='false'>       ...     </child1>   </parent3> </root> 

using following xpath expression: //*[@mycond='true'] gives [parent1, parent1/child2, parent2/child2, parent3].

i'm looking way filter out parent1 has decedent parent1/child2 in list.

just add predicate: there no descendant true condition.

//*[@mycond='true'][not(descendant::*[@mycond='true'])]  

or, equivalently,

//*[@mycond='true' , not(descendant::*[@mycond='true'])]  

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo