开发者

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

开发者 https://www.devze.com 2022-12-26 04:56 出处:网络
how to select an element based on an order and dependent of its existence in XPath ? For example how to select the best quality video if it exist.

how to select an element based on an order and dependent of its existence in XPath ? For example how to select the best quality video if it exist.

<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 doesn't exist

this case can exist (the videos names can be random):

<VIDEOS>
    <LOW_RES>video_L.flv</LOW_RES>
    <HI_RES>vi开发者_开发技巧deo_H.flv</HI_RES>
    <HD>video_hd.mp4</HD>
</VIDEOS>

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


Use:

/*/HD[text()]
|
 /*/HI_RES[text() and not(../HD/text())]
|
 /*/LOW_RES[text() and not(../HD/text()) and not(../HI_RES/text())]
0

精彩评论

暂无评论...
验证码 换一张
取 消