I think the issue could be around this line here
<xsl:apply-templates select="./@*"/>
In particular, its position, which is after you have created the c element in the template. Attributes should be added on to an element before any child elements. Indeed, I am surprised you are not getting an error along the lines of "Attribute nodes must be added before any child nodes to an element."
Assuming you do want the attribute added to the a element, try the following
<xsl:template match="a">
<a>
<xsl:apply-templates select="@*"/>
<c>
<xsl:call-template name="gcd">
<xsl:with-param name="nums" select="./b/@d"/>
</xsl:call-template>
</c>
<a>
</xsl:template>
This should then give consistent results.
And if you don't want the attributes, simply remove the apply-templates