Kazakhstan Transit visa
Transit visas through the territory of Kazakhstan (for 5 days) are issued with the presence of a visa to a third country (the visiting country) and ticket (ticket for travel through the territory of Kazakhstan).
So you need visa of the country you are going to, and ticket. Note that you must register during first 5 days in Kazakhstan. You can do it right in airport:
Customers may receive Kazakhstan transit visa (at the embassy of Kazakhstan in Almaty) airport without invitation, as long as they have visa and through air or railway tickets to a third country.
You may need to push hard. In my experience they will start by saying you can't do it, but will eventually concede. The other problem at Almaty airport is that you need the embassy guy to be there to issue the visa. If you arrive at night he will probably have gone home!