xpath - 条件表达式

时间:2012-11-29 09:09:43

标签: xpath

我有以下文件:

<Ships>
   <Class name = "Kongo" >
        <Ship name "Kongo" launched = "1913" />
        <Ship name = "Hiei" launched = "1914"/>
        <Ship name = "Haruna" launched = "1915" />
   </Class>
   <Class name = "North Carolina">
        <Ship name = "Washington" launched= "1941"/>
   </Class>
</Ships>

我需要找到与他们班级同名的船只的年份 推出。哪个应该是

/Ships/Class/Ship[..]/@launched

'...'部分已被省略,因为它应该是一个条件,指定船名等于其类名的位置。有谁知道如何引用更高级元素的属性?查询应返回'1913'

1 个答案:

答案 0 :(得分:3)

Ships/Class/Ship[@name = ../@name]/@launched