xmlstarlet: filter out element with attribute

有些话、适合烂在心里 提交于 2019-12-06 12:01:08

Unfortunately, xmlstarlet's sel doesn't support apply-templates, but you can use the ed command for this:

xmlstarlet ed -d '/database//some[@name != "A"]' input.xml

Write an XSLT stylesheet doing

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>

<xsl:template match="some[@name != 'A']"/>

</xsl:stylesheet>

then call xmlstarlet to apply that stylesheet to your input XML: xmlstarlet tr sheet.xsl input.xml.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!