Let's look at the variable declaration:
<xsl:variable name="test" >
<xsl:value-of select="AttrName"/>
</xsl:variable>
This is a very convoluted way of writing:
<xsl:variable name="test" select="AttrName" />
What you want is a string, but instead of defining the variable as a string you are evaluating the string, putting the result into a text node, attaching that text node to a document node, and then computing the string value of the document node every time you reference the variable. If you don't care about performance and if you are bonused on the number of lines of code you write, this is fine, but otherwise it's horrible. Can't blame you though, it's an incredibly common blunder: yours is the second post this morning on this forum to do it.
Now your test. In your sample data you have <AttrName></AttrName>. The string value of that element is a zero-length string. But your test is
<xsl:if test="$test = ' ' ">
which tests for a string containing a single space. You need
<xsl:if test="$test = '' ">
Or if you want to test for all strings containing no characters other than whitespace, use
<xsl:if test="not(normalize-space($test))">
Of course you could also do this in the variable:
<xsl:variable name="test" select="normalize-space(AttrName)" />
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference