I'm trying to update all nodes with the same pattern using xmlstarlet. Given the following xml
<root>
<application>
<provider name="alpha" value="my.corp.lion" />
<provider name="beta" value="my.corp.tiger" />
<provider name="gamma" value="my.corp.monkey" />
</application>
</root>
I can currently update each node as follows
oldCorp="my.corp"
newCorp="new.my.corp"
myNode="/root/application/provider[@name='alpha']/@value"
oldValue=$(xml sel -t -v ${myNode} MyXml.xml)
newValue=${oldValue//$oldCorp/$newCorp}
xml ed --inplace -u ${myNode} -v "${newValue}" MyXml.xml
# results in provider.alpha being new.my.corp.lion
What I'd like to be able to do however is foreach ALL provider nodes and update the final xml result to be
<root>
<application>
<provider name="alpha" value="new.my.corp.lion" />
<provider name="beta" value="new.my.corp.tiger" />
<provider name="gamma" value="new.my.corp.monkey" />
</application>
</root>
Is there a way to do a foreach over the providers
and replace all my.corp
instances with new.my.corp
?