sed -n 's/\s*<species [^>]* id="\([^"]*\).*/\1/p' species.xml |\
cat -n |\
sed 's/\s*\([0-9]\+\)\s*/id\1 /' > ids.txt
cp species.xml my_species.xml
while read a b
do
sed -i 's/"'"$b"'"/"'$a'"/g' my_species.xml
done < ids.txt
Assuming your XML file is nicely formatted (i.e., each tag is all on one line), you can get away with sed and bash. Otherwise, you'll need a language with an XML parser. The same approach will work, but the details will vary.
Make a map of ids to replacements. Then, each time you encounter an id you've seen before, you look it up and replace it.
The sed
line above maps each id from a <species>
tag to a numbered id (the backslashes allow the line to be split over several lines for readability).
The file is copied to prevent modifying the original.
As each line is read from the id map file, all occurrences of the original id are replaced with the new, numbered id.