Well, there seems to be more than one difference to me: one template is outputting key, apiNode, and apiImport, while the other is outputting key and display. To me, there doesn't seem to be enough commonality to justify making a single template with conditional logic. But you can always do it if you want: create a single template with four parameters and four calls on xsl:attribute, each surrounded by xsl:if:
<xsl:if test="$key != ''">
<xsl:attribute name="key">
<xsl:value-of select="$key"/>
</xsl:attribute>
</xsl:if>
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference