It works, but not exactly as you described it. If a Pokemon is caught or hatched in one save and transferred to a save with a different name, trainer ID, and secret ID, it will gain 1.5 times as much experience from the same battle. Also, if you don't like grinding, and you're grinding to beat a particular trainer, just battle that trainer over and over again until you win. It's faster that way.
source