You haven't understood the concept that xsl:for-each changes the context node, and relative path expressions start from the context node.
This means that the context node is now an attribute, the @name attribute. (Also note, HEADER is the outermost element of your document, so you don't need to search the whole document to find it. Use /HEADER rather than //HEADER).
@name is a relative path expression, it looks for an attributes of the context node called name. But attributes don't have attributes, so it won't find one. You want test=". = $LINK".
This is a so-called "absolute path expression". It doesn't start from the context node, it starts from the root. So you're selecting all the TITLE elements, not just the one for the selected LINK. You want the TITLEs of the LINK that's the parent of the selected attribute: select="../TITLE". Or most people would do it like this:
<xsl:attribute name="HREF">test<xsl:value-of select="TITLE"/>test</xsl:attribute>
<xsl:value-of select="@name" />
Go back to the spec or your favourite reference book, and reread the section about the context node.
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference