Try
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="el-by-idref" match="Elements/Element" use="@idref"/>
<xsl:template match="XML">
<xsl:copy>
<xsl:apply-templates select="Model/packedElement"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Model/packedElement">
<content comment="{key('el-by-idref', @id)/Attributes/@comment}" id="{@id}" test="{@id}"/>
</xsl:template>
</xsl:stylesheet>
that way you get
<XML>
<content comment="comment 1." id="1" test="1"/>
<content comment="comment 2." id="2" test="2"/>
<content comment="comment 3." id="3" test="3"/>
</XML>