The government says the law, which stems from European Union directives, aims to encourage online commerce by making the Internet a safer place to do business. It wants companies operating on the Internet to be subject to the same tax and commerce laws as traditional firms.
Even without this new law, if you had a business, you were already subject to tax and commerce laws. You can't start a business on the internet selling goods or services in Spain and then don't take any responsability as regards the Spanish laws.
In addition to being compelled to sign up with the government's mercantile register, the law requires websites that carry out commercial transactions to display a company address and tax number. The idea is to give customers a physical place to turn if a problem arises.
As you can read from a press note of the Ministery of Science and Technology
see here if your business does not have to be at the mercantile register, then the new law doesn't create a new need for it.
I can't see any problem on displaying your company's address unless your business is something not very legal. As it says above, the aim is to protect customers and allow them to know who they are dealing with.
The law would also apply to foreign-hosted websites if the people transacting business on them are physically in Spain.
El viajero, there you have the answer to your question. My website and my domain name are both hosted with a US company. Obviously, my hostel is located in Spain and thus I am subject to Spanish laws. Or should someone be subject to a foreign tax laws when his business and/or services are in your country.
Even not-for-profit sites that take in revenue say, from advertising banners, are considered to be doing business, even if they operate at a loss.
And while such sites don't have to register, the government says, they do have to publish the webmaster's name, address and national identification number
Again, I don't understand the fear to show who they are.
Other provisions of the law oblige Internet access providers and websites to store customers' "connection and traffic data" for up to a year.
This one is technically quite difficult to comply with. Keeping a log of all internet connections will take a large amount of disk space.
Providing that access to that information requires the authorization of a judge, then I understand that is a way to stop criminals from using Internet anonymity to hide themselves when contacting their accomplices.