I am not totally sure what you are trying to do, but I can't help thinking you are going about it the wrong way.
If what you are trying to do is replace the link text that is shown to the user in
so it becomes
then why not try something a bit simpler:
which breaks it into groups: those with tags, and those without.
You can then only change the "data" group items.
If that isn't what you are trying to do, then please give us better detail.