Xpath 基于值的XMLStarlet返回属性(反向查找)
我有以下xml:Xpath 基于值的XMLStarlet返回属性(反向查找),xpath,xquery,xmlstarlet,Xpath,Xquery,Xmlstarlet,我有以下xml: <block name="http-www.example.com"> <mapentry tag="AB12">bottlecap</mapentry> <mapentry tag="CD45">description goes here</mapentry> <mapentry tag="GH23">12345</mapentry> <mapentry tag="JK8
<block name="http-www.example.com">
<mapentry tag="AB12">bottlecap</mapentry>
<mapentry tag="CD45">description goes here</mapentry>
<mapentry tag="GH23">12345</mapentry>
<mapentry tag="JK89">54321</mapentry>
</block>
有没有办法搜索该值?也许这就是您想要的
xmlstarlet sel -t -v "//mapentry[. = 'bottlecap']/@tag" "mytest.xml"
对非常感谢。我不知道这个[.='xx']语法。那太好了!
xmlstarlet sel -t -v "//mapentry[. = 'bottlecap']/@tag" "mytest.xml"