Xslt replace function

Is there a neat way of replacing chars in an xml file eg " " (whitespace) is replaced with the entity " ". Or should a xslt template be used?