You don't have an xsl:apply-templates
so you never get past that first root element. Also, node()
includes text, comments, and processing instructions and you don't want to try to create an attribute if you match one of those.
Try something like this instead...
XSLT 1.0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[a]">
<xsl:copy>
<xsl:apply-templates select="@*|a/a"/>
<xsl:apply-templates select="node()[not(self::a)]"/>
</xsl:copy>
</xsl:template>
<xsl:template match="a/a" priority="1">
<xsl:attribute name="{a}">
<xsl:value-of select="v"/>
</xsl:attribute>
</xsl:template>
<xsl:template match="v">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
Output
<foobar atr0="NO" atr2="NO">
<foo atr1="NO" more="more">ONE</foo>
<bar atr6="ATR">
<baz attr="123" attr222="22">TWO</baz>
</bar>
</foobar>