Also note, that if you're using this with an attribute of type XML Field, you'll get the output HTML tags in the $output variable, so it could cause you some headache if you use i18n on it.
--
Nothing is impossible. Not if you can imagine it!
The reason why the $output has a lot of spaces is because there's a lot of spaces in your code. All the content that is inside the {set-block} gets in the $output variable, including all the whitespaces in it.
But yes, trim() is the sollution. You can do it even in a more compact way:
{$output|trim()|i18n('core/shop')}
--
Nothing is impossible. Not if you can imagine it!