This is a standard grouping problem. In XSLT 2.0 you can solve such problems using <xsl:for-each-group>, for example
<xsl:template match="Vendor">
<vendor>
<xsl:for-each-group select="contact" group-by="@Id">
<contact>
<xsl:copy-of select="@*, current-group()/Phone"/>
</contact>
</xsl:for-each-group>
</vendor>
</xsl:template>
Grouping problems are much more difficult in XSLT 1.0, but there is a standard coding pattern called Muenchian grouping for solving them; you can find details in any good XSLT book or at
http://www.jenitennison.com/xslt/grouping
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference