Yes, this will work.
An original DS or DS Lite has a slot for GBA cartridges, you can transfer from Gen 3 to Gen 4 using one DS with a Gen 4 game and a Gen 3 game both inserted. Note that whichever Gen 4 game you use, you must have progressed far enough in the game to unlock the ability to receive the transferred Pokemon.
For Gen 4 to Gen 5, you can use any combination of DS and 3DS systems. Also be aware that some Gen 5 titles from other regions may not work with DSi or 3DS, so check the language and region of your Gen 5 game first.