Two issues here. Firstly, variables in XSLT aren't macros: they represent values, not bits of expression text. If you want to test a variable name in a path expression, you can't write a/$b, you have to write a/*[name()=$b]. Secondly, though, in XSLT 1.0 there's a specific ban on using variables in the match pattern of a key. This is to prevent circularities where the variable depends on the key and the key depends on the variable.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference