xmlstarlet:select 属性(如果子项存在)

xmlstarlet: select attribute if child exists

我有一个 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

我一直在研究条件,但我找不到 select ginkscape:label 只有包含 path 的方法节点 [或者,如果它不包含 image 节点]。

要仅获得具有 child pathg,您只需在 g 的谓词中添加 path :

//_:svg/_:g[_:path]/@inkscape:label