I am trying to prefix the TEXT_VALUE
field's values by a number in incremental way in all my xml files only the tags called "TRANSL" with ID="Example".
Currently I am doing it manually, but since I have several thousands of them, I think I should do it programmatically.
here is the initial version:
<TRANSL ID="Example">
<TRANSCIPT>
<REF_TEXT TEXT_ID="a680" TXT_TM="a24">
<TEXT_VALUE>this is an example</TEXT_VALUE>
</REF_TEXT>
</TRANSCIPT>
<TRANSCIPT>
<REF_TEXT TEXT_ID="a681" TXT_TM="a25">
<TEXT_VALUE>another example</TEXT_VALUE>
</REF_TEXT>
</TRANSCIPT>
<TRANSCIPT>
<REF_TEXT TEXT_ID="a682" TXT_TM="a26">
<TEXT_VALUE>third example</TEXT_VALUE>
</REF_TEXT>
</TRANSCIPT>
</TRANS>
and here is the edited version of how it should look like:
<TRANSL ID="Example">
<TRANSCIPT>
<REF_TEXT TEXT_ID="a680" TXT_TM="a24">
<TEXT_VALUE>1-this is an example</TEXT_VALUE>
</REF_TEXT>
</TRANSCIPT>
<TRANSCIPT>
<REF_TEXT TEXT_ID="a681" TXT_TM="a25">
<TEXT_VALUE>2-another example</TEXT_VALUE>
</REF_TEXT>
</TRANSCIPT>
<TRANSCIPT>
<REF_TEXT TEXT_ID="a682" TXT_TM="a26">
<TEXT_VALUE>3-third example</TEXT_VALUE>
</REF_TEXT>
</TRANSCIPT>
</TRANS>
how can I do it programmatically? is there any professional xml editors out there? If not, How can I do it in python, or powershell, perl, notepad ++, or any other, for example?
here is my script in python as a notepad ++ plugin:
def increment_replace(match):
return "<TEXT_VALUE>{}".format(str(int(match.group(1))+1))
editor.rereplace(r'\<TEXT_VALUE\>', increment_replace)
but it is not working...