Since xsl:copy copies the current element and not the attributes, you need to tell it to copy the attributes.
This will copy any arbitrary attribute:
<xsl:template match="@*"> <xsl:copy/> </xsl:template>
So, we can fix the last example to get the attribute copied with the following templates:
<xsl:template match="credit-card"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:text>XXXX-XXXX-XXXX-XXXX</xsl:text> </xsl:copy> </xsl:template> <xsl:template match="@*"> <xsl:copy/> </xsl:template>