Xpath how to select an element based on order and depends on its existence

how to select an element based on order and depends on its existence in XPath? For example, how to choose the best quality video if it exists.

<VIDEOS>
    <LOW_RES>video_L.flv</LOW_RES>
    <HI_RES>video_H.flv</HI_RES>
    <HD/>
</VIDEOS>

this should return video_H.flv because the hd version does not exist

this case may exist (video names may be random):

<VIDEOS>
    <LOW_RES>video_L.flv</LOW_RES>
    <HI_RES>video_H.flv</HI_RES>
    <HD>video_hd.mp4</HD>
</VIDEOS>

this should return video_hd.mp4 because the hd version exists. Many thanks.

+5
source share
1 answer

Using

/*/HD[text()]
|
 /*/HI_RES[text() and not(../HD/text())]
|
 /*/LOW_RES[text() and not(../HD/text()) and not(../HI_RES/text())]
+2
source

All Articles