Just as a quick explanation/thought exercise. Spain vs The Netherlands
Spanish troops are more numerous, have better equipment per man (Something Akin to the Model 1857 Rifled Musket, caplock grenades with shrapnel) but have poor morale. Their decently if not tremendously trained, but have issues with their pay, rations, etc. that make them considerably more likely to decide a fight just isn't worth it.
On the other side, the Dutch, man for man, fight far worse, better trained but with far less effective weapons, but have invested in a skilled Artillery Corps that is quite possibly best in the world.
Compare Gibraltar to Sicily.
At Gibraltar, the initial garrison was scattered or killed by artillery, but the reinforcements, despite not taking the city back, have not allowed a Dutch breakout because they're entirely willing to stand in trenches to negate the Dutch artillery advantage, and so long as they aren't out of range, getting cut to shreds in the open, they stand.
In Sicily, the rioters provided a IDEOLOGICAL reason for the garrison to fight, and even against fairly well equipped troops, and outnumbered by the mob, the Spanish stood, did tremendously well, and shattered the revolt quite quickly.