Conditionals in XML file using xmlstarlet

雨燕双飞 提交于 2019-12-06 14:42:47

In addition to not needing conditionals (-i), it's also not really necessary to match (-m) either; just get the value (-v)...

xmlstarlet sel -t -v "/*/book[Description/stock='YES']/Location/shelf" -n book.xml

Not need to use conditionals:

With this one I get the author that have books in stock

xmlstarlet sel -t -m "/bookstore/book/Description[stock='YES']" -v author -n book.xml

This will give all the shelves. Getting closer, but not exactly what we want

xmlstarlet sel -t -m "/bookstore/book/Description[stock='YES']" -v "/bookstore/book/Location/shelf" -n book.xml

This one finally, will give you the shelves of the books that are in stock

xmlstarlet sel -t -m "/bookstore/book[Description[stock='YES']]" -v "Location/shelf" -n book.xml
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!