xmlstarlet select value based on condition

空扰寡人 提交于 2019-12-06 02:31:26

Building on your first command, you should be able to apply a simple XPath predicate on project to filter it by artifactId element value :

xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t \
    -v "/x:project[x:artifactId='iwidget']/x:groupId" < pom.xml

Regarding the use of variable, you need to wrap it with quotes so that the value will be recognized as string literal by the XPath processor :

xmlstarlet sel -N x=http://maven.apache.org/POM/4.0.0 -t \
    -v "/x:project[x:artifactId='$VAR']/x:groupId" < pom.xml
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!