xml - XPATH return with no child tag and child tags of specific value -
new xpath, have following xml:
<lessons> <lesson>blah</lesson> <lesson>blah</lesson> <lesson>blah</lesson> <lesson> <a>yes</a> </lesson> <lesson> <a>no</a> </lesson> <lesson> <a>booyah</a> </lesson> <lesson> <a>wowzer</a> </lesson> </lessons>
what want select lessons no <a>
tag, , lessons <a>
tag having text yes. others excluded.
how can accomplish this?
if description of requirement reads "return x, excluding have y", need predicate.
simply use following xpath expression:
/lessons/lesson[not(a = 'no')]
assuming well-formed input document (yours not, because 1 of lesson
elements not closed), result (individual results separated --------
):
<lesson>blah</lesson> ----------------------- <lesson>blah</lesson> ----------------------- <lesson>blah</lesson> ----------------------- <lesson> <a>yes</a> </lesson> ----------------------- <lesson> <a>booyah</a> </lesson> ----------------------- <lesson> <a>wowzer</a> </lesson>
cause want yes, , exclude else in no or other value
then use
/lessons/lesson[a = 'yes']
and result (obviously):
<lesson> <a>yes</a> </lesson>
if meant select lesson
elements if not have a
child element @ all, use
/lessons/lesson[a = 'yes' or not(a)]
and result be
<lesson>blah</lesson> ----------------------- <lesson>blah</lesson> ----------------------- <lesson>blah</lesson> ----------------------- <lesson> <a>yes</a> </lesson>