<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
 <xsl:output indent="yes"/>
 <xsl:template match="Root">
  <root>
   <xsl:apply-templates
select="/Root/row[@EmployeeID=@ReportsToEmployeeID]"/>
  </root>
 </xsl:template>
 <xsl:template match="row">
  <Employee EmployeeID="{@EmployeeID}" FirstName="{@FirstName}">
   <xsl:apply-templates
select="//row[@ReportsToEmployeeID=current()/@EmployeeID and
@ReportsToEmployeeID!=@EmployeeID]"/>
  </Employee>
 </xsl:template>
 </xsl:stylesheet>