【问题标题】:xmlstarlet: select attribute if child existsxmlstarlet:如果孩子存在则选择属性
【发布时间】:2017-05-17 05:14:20
【问题描述】:

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

我一直在研究条件,但我找不到选择 ginkscape:label 的方法,前提是它包含 path 节点 [否则,如果它不包含image节点]。

【问题讨论】:

    标签: xml svg xpath xmlstarlet


    【解决方案1】:

    要仅获取具有子pathg,您只需在g 的谓词中添加path

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-05-19
      • 2012-07-03
      • 1970-01-01
      • 2023-01-22
      • 2020-02-05
      • 1970-01-01
      • 2011-06-28
      • 2014-02-21
      相关资源
      最近更新 更多