Dear Jayesh,
Since the company has changed, the employee would be eligible for gratuity for 6 years for working in the ABC company on the basis of salary last drawn in the ABC company.
Further, since his service in the XYZ does not fulfil the condition of 5 years of qualifying service, he is not eligible for any gratuity in the XYZ.
It is immaterial that both the companies are working in the same building or under the same director. As per law these are two separate bodies/entities. However, if the employee was shifted to XYZ company with spcific mention of transfer from one company to other company for spcific purpose, the case can go in favour of the employee to get benefit of 3 years of additional service in XYZ.
In fact it is normal practice of some companies to avoid terminal benefits or to save expenditure on establishment, they usually try to shift employees from one company to another without assigning any reason.
So, you will have to check the background of shifting of the employee.