The GAAR takes the spirit of the law into consideration when considering whether the law has been broken.
The Ramsey Principle (first stated with respect to a case governing circular transactions) also raises the spirit of the tax law being superior to the strict rules based interpretation.
That said, when it comes to most tax law the mischief rule doesn't apply (because in principle it needs to be dealing with a limitation of the common law). The golden rule rarely comes into play with tax law (though consider the case of murdering a parent and the consequences on inheritance tax, for example). So yeah, the literal rule almost always applies.
Should we force companies to repatriate all foreign-earned profits?
If yes, then the US will lose its economic advantage. No international company would be insane enough to incorporate in the US.
If no, then we have our current situation.
IMO the tax law itself is broken, not Apple’s response to asinine laws. Remember that Apple has not violated the law. I also agree with the comment you replied to - for tax law, there should not be a difference between the law and the intent. What is written is what needs to be followed. And right now Apple is following it to the letter of the law.
HMRC's essentially disagreed with the spirit was being followed in this case and Google paid up:
In other words, for tax there is no distinction between the spirit and letter of the law. They’re one and the same.