Imaginative, but completely wrong. xsl:attribute creates an attribute node in the result tree, not in the stylesheet.
If you want to construct an XPath expression as a string at run-time and then evaluate it, you need an extension such as saxon:evaluate().
On the other hand if the variable $XMLNodeName_announcements simply holds an element name, you can do
Code:
<xsl:for-each select="data/*[name()=$XMLNodeName_announcements]"/>
.