I know that XSLT includes an <xsl:attribute-set> element where you can predefine a set of attributes (e.g. 'name' and 'value'), plus a 'use-attribute-sets' attribute on the <xsl:element> element where you can add those attributes to a particular element.

Now if you could just work an XSL transformation step into your processing at the right time, this might be the basis of a solution.