1

I would like to iterate over many xml files to fix outdated configuration entries by getting all matches and replacing then in a second step every entry by updated strings (multiline scripts in this case). I'm aware how to query/select and print element's values using XPath with xmlstarlet e.g.

xmlstarlet sel -t -v '//hudson.tasks.Shell/command' $xml

or how to list all the XPaths using

xmlstarlet el -a $xml

Is there a way to output a list of valid XPaths expressions for every match to use this XPath string later to update the value in the second step? e.g.

maven2-moduleset/postbuilders/hudson.tasks.Shell[1]/command
maven2-moduleset/postbuilders/hudson.tasks.Shell[2]/command

The only solution I found for now was to count the paths from eloutput and then to loop over them by index (using bash).

Heiko Robert
  • 111
  • 3
  • For `xmlstarlet` you could try my own [answer](https://stackoverflow.com/a/72668093/14403369) at `stackoverflow.com`. For an XSLT 1.0 stylesheet try [this](https://stackoverflow.com/a/4747858 "Generate/get xpath from XML") SO answer. – urznow Sep 23 '22 at 13:13

0 Answers0