I gave up trying to automate this. Here's what I ended up doing:
Set up a macro in my text editor to remove all the OpenCPN GPX extensions, leaving just the needed data under <rtept...>.
Set up a macro to remove the carriage returns and leading blanks on each of these lines, making one line for each route point.
Copied the column of route point names to an Excel worksheet.
Changed the first point to "001". Did a "fill sequential" on the rest of the column.
Added a column to the left with the route abbreviation. Did a "fill down" on the rest of the column.
Copied to two columns to a new file in my text editor.
Removed the tabs between the columns.
Still in the text editor, copied the merged column back over the route names in the original, flattened GPX file.
Opened the flattened and edited GPX file in OpenCPN.
Exported the GPX file back out again, restoring the carriage returns and spaces.
It's a stupid amount of work
for such a simple thing, but still easier than writing a new program to read, edit and re-save the GPX file. And really, with macros and the search-and-replace capabilities of a decent text editor, each file took only a minute or less.
I already had the macro to remove all the extensions. It saves a ton of space. I don't know why OpenCPN doesn't have some options for what to include or omit in exported GPX files.
how applications come and applications go, and the technology changes and improves every year, but I still come back to an old-fashioned text editor, to do the same type of thing, decade after decade.