You could shorten
<xsl:attribute name="xml:id">
<xsl:text>foo</xsl:text>
</xsl:attribute>
to
<xsl:attribute name="xml:id">foo</xsl:attribute>
But other than that your approach is fine. And your version might be preferred for readability.