Namespace-related bugs are a pain in the neck. You can avoid a large class of them by pretending that the name() function never existed (and avoid using it).
How do you control how your query or stylesheet results will be serialized (encoding, indentation, etc.)? There are several options for controlling output options.