I'm attempting to count the number of tags that have a certain value

Bits of your code aren't formatted as code so we're missing indentation, etc. See Wiki - how to post code on this forum and then you can edit your post to fix it.