As always this kind of thing is easier in XSLT 2.0. You don't state any constraints that prevent a 2.0 solution so I'll go with that.
It feels like this:
<xsl:key name="dp" match="stuff/*" use="@name"/>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="key('dp', string-join(ancestor-or-self::*/@name, '.'), doc('stuff.xml'))/(@id, text())"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference