我有一个svg,其中包含以下内容(已精简):
<svg
xmlns="http://www.w3.org/2000/svg"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape">
<g
inkscape:label="base"
inkscape:groupmode="layer"
id="layer1"
transform="translate(0,-600)">
<image
sodipodi:absref="/Untitled.png"
xlink:href="/Untitled.png"
width="800"
height="500"
preserveAspectRatio="none"
id="image5168"
x="3.67"
y="596" />
</g>
<g
inkscape:groupmode="layer"
id="layer30"
inkscape:label="triangle">
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="M 273,340 290,127 563,307 Z"
id="path5174"
inkscape:connector-curvature="0" />
</g>
</svg>
Complete XML
当我查询:
xmlstarlet sel -t -v "//_:svg/_:g/@inkscape:label" drawing.svg
我得到:
base
triangle
我一直在研究条件语句,但是只有找到
g
的inkscape:label
节点时,我才能找到一种选择方法;否则,如果不包含path
节点]。
最佳答案
要仅获取具有子g
的path
,只需在path
的谓词中添加g
即可:
//_:svg/_:g[_:path]/@inkscape:label
关于xml - xmlstarlet:如果子级存在,则选择属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41437971/