Keeping Spain a major power?

With a POD as far back as 1700, find a way to keep Spain a major power. Bonus points if you can manage this even with them lossing parts of their empire to revolutions.
 
Have the 19th century turn out better for them. The instability of 19th century Spain made it an even more sick man than the Ottomans.
 
Top