left up right
In XSLT 1.0
<xsl:for-each select="author/@affiliation"> 3 of these
 <xsl:variable name="aff" select="."/>
 <xsl:if 
  test="count(parent::author/preceding-sibling::author[@affiliation = $aff]) = 0">
  <affiliation>
   <xsl:attribute name="name" ><xsl:value-of select="."/></xsl:attribute>
   <xsl:copy-of select="parent::author" /> outputs first
   <xsl:copy-of                            and the rest
     select="parent::author/following-sibling::author[$aff = @affiliation]" />
  </affiliation>
 </xsl:if>
</xsl:for-each>