I am not sure what you are saying, and not sure if you are asking a question. But to be clear, there are two separate requirements. One has to do with the space in front of the panel. You need to keep clear the space that is at least 30" wide, at least 36" deep (more, depending on certain conditions), and 6-1/2 feet high from the floor. This area is reserved for working space for a future maintenance person to use. The other has to do with the areas directly above and below the panel. The area below has to be free of foreign piping or other items all the way to the floor. The area above has to be free of foreign piping or other items for a distance of 6 feet above the top of the panel. These areas are reserved for future installation of conduits.
In the installation under discussion, a transformer would not be "foreign" to the panel. Therefore, it can be placed directly above the panel, and need not be 6 feet higher than the top of the panel. If, however, it sticks out from the wall more than 6 inches further than the panel sticks out from the wall, then the bottom of the transformer cannot impede upon the working space headroom requirement of 6-1/2 feet.