You can't do it the way you are suggesting in XSLT, as variables cannot be updated. However you should be able to use the calculation which works out if it should display 'HEADER' to simply count the number of times that that would be displayed.
in your template do something like this:
and then at the bottom:
There are <xsl:value-of select="count(//@Id='AB')"/> headers
/- Sam Judson : Wrox Technical Editor -/