我正在尝试从以下xml代码段中检索表行。导致代码段的路径为//html/body/div/div/div
。我需要选择/table/tr/th/a@title='Music genre'
我可以选择tr行:
xmlstarlet sel -t -v "//html/body/div/div/div/table/tr/th/a[@title='Music genre']" Unwritten_Law
我可以选择数据行:
xmlstarlet sel -t -v "//html/body/div/div/div/table/tr/td/a" Unwritten_Law
我需要做的是只选择tr行是音乐流派的数据行
<table class="infobox vcard plainlist" style="border-spacing:3px;width:22em">
<tr>
<th colspan="2" style="text-align:center;font-size:125%;font-weight:bold;background-color: #b0c4de"><span class="fn org">Unwritten Law</span></th>
</tr>
<tr>
<th scope="row" style="text-align:left">Origin</th>
<td><a href="/wiki/San_Diego,_California" title="San Diego, California" class="mw-redirect">San Diego, California</a>, U.S.</td>
</tr>
<tr>
<th scope="row" style="text-align:left"><a href="/wiki/Music_genre" title="Music genre">Genres</a></th>
<td><a href="/wiki/Pop_punk" title="Pop punk">Pop punk</a>, <a href="/wiki/Punk_rock" title="Punk rock">Punk rock</a>, <a href="/wiki/Skate_punk" title="Skate punk">Skate punk</a>, <a href="/wiki/Post_grunge" title="Post grunge" class="mw-redirect">Post grunge</a>, <a href="/wiki/Alternative_rock" title="Alternative rock">Alternative rock</a>, <a href="/wiki/Melodic_hardcore" title="Melodic hardcore">Melodic hardcore</a></td>
</tr>
<tr>
<th scope="row" style="text-align:left">Years active</th>
<td>1990–present</td>
</tr>
</table>
答案 0 :(得分:0)
考虑到问题中的片段:
xmlstarlet sel -t -v "/table/tr[th/a/@title='Music genre']/td/a" Unwritten_Law
输出
Pop punk, Punk rock, Skate punk, Post grunge, Alternative rock, Melodic hardcore
根据需要添加/html/body/div/div/div
。