Don't think in terms of variables and loops, that kind of procedural thinking is too low-level for XSLT. You need to think of the output as a function of the input: the class is "on" for odd-numbered elements and "off" for even-numbered. That translates into
if (position() mod 2) = 1
then "on"
else "off"
Exactly how you express that depends on whether you're using 1.0 or 2.0 and where it fits in your stylesheet code, but I hope you get the idea.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference