The so called "loopholes" Apple is exploiting is only really open to multi-national companies.
For example, here in Sweden, Apple has a datacenter, sell products through Apple Sweden and have people employed.
To enable Swedish companies to make money, government has made laws so that tax can be offset. If you have costs to make profit, that cost can be offset against your profit which means lower tax.
What Apple can is to legally do what is illegal if you only operate in one country: invoice yourself.
Apple Europe is based in Ireland. Every product sold in Sweden, Apple Sweden buys from Apple Europe in Ireland. By making sure that the prices of products (including IP) Apple Europe sell to Apple Sweden is high enough, any profit made in Sweden is offset by the high cost of buying said products from Apple Europe. If the products are priced high enough, Apple Sweden will start loosing money, which means you can offset that loss against other taxes you would have to pay.
That is sort of how taxation works in most countries. Since countries only have jurisdiction over their own taxes, it's impossible to stop multi-national companies to exploit this, unless governments would change tax law so that it would severely hurt businesses only operating in their own country.
Now Apple Europe is rich, but hey, Apple does not want to pay the low taxes in Ireland either, so they set up a company in a tax haven that owns all the IP and invoices Apple Europe for "licensing" the IP. Hence, no tax due anywhere except for the tax haven which, as the name imply, does not charge company tax, or a very low tax.
This option is really just open to multi-national companies and the filthy rich who can pay a shady, but perfectly legal company based in one of these tax havens to run a business which is no more than a PO Box.
The Paradise Leak has listed rich people besides huge companies.
Of course, this is actually doable even for the average Joe, but he/she seldom have the ability to work out all the details to set up a company, start your tax haven company and start billing yourself. And, it would be a real hassle every time you have to pay your rent.
The only reason Apple is lobbying for the tax holiday in the US is that they are starting to get worried that the tax havens are getting fewer and fewer. The low company taxes were put in place in hope that it would attract companies and actually make money for these countries which usually are extremely small and have no natural resources and a very small population that cannot spawn the next Apple.
Now as they see billions and billons of dollars being stashed with no benefit to the country, they are starting to rethink their tax laws. These dollars though are as real as vapor and could be gone within minutes, should the laws change.
Apple and a horde of other companies and rich people are doing their very best to get that tax holiday as they recon it's better to pay that 5% tax once and have the money secured than pay no taxes but risk having to pay a lot more, should tax havens go away. If they were confident that their money would be safe and non-taxed in these off-shore places, they couldn't care less about taxes in Europe or the US.
So, yes, Apple is paying all the taxes they legally owe, but only because they're not one company but hundreds acting as if they were independent although it's just fiction.