Concatenate a value to an existing xml attribute using XMLStarlet (Image Annotation)

倾然丶 夕夏残阳落幕 提交于 2019-12-24 07:37:51

问题


I am working on annotating images using xml. I am using xmlstarlet and unix bash commands but I am facing some issues when I try to append a value to an existing xml attribute value. For example, I have <filename>a</filename> and I want to make it <filename>a.jpg</filename> (i.e. concatenate '.jpg' to the existing value).

I used the following piece of code but it totally overwrites the value (i.e. <filename>.jpg</filename>.

Script:

for name in *.xml; do xmlstarlet ed --inplace -u '/annotation/filename' -v .jpg "$name"; done

回答1:


xmlstarlet solution:

xmlstarlet ed -L -u '//annotation/filename' -x 'concat(., ".jpg")' input.xml

Quick guide: xmlstarlet ed --help



来源:https://stackoverflow.com/questions/48904096/concatenate-a-value-to-an-existing-xml-attribute-using-xmlstarlet-image-annotat

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