Attributes can also be created by xsl:attribute.
They must be created before children are added to the element.
You can use them on literal elements:
<section> <xsl:attribute name="id">sect1</xsl:attribute> </section>
Or on xsl:element constructions
<xsl:element name="section"> <xsl:attribute name="id">sect1</xsl:attribute> </xsl:element>
The children of xsl:attribute must be text nodes that represent the value of the attribute.
You can use expressions in the name:
<xsl:attribute name="{child/@ref}"/>