I have a servlet filter in my application that intercepts all the incoming requests and tries to strip the whitespaces from the incoming XML and write the resulting \'clean\
Adding this as a second answer, because the explanation in the first one is still (hopefully) informative enough to keep it.
Assuming that by "trim" you mean "remove all whitespace immediately after opening and before closing tags", then the following additional template rules should do the trick: