I am using .NET to transform XML from a DataSet to the sitemap format. Here is where I am at right now. As you can see, I create the root element with the correct namespace. I noticed that if I created child nodes, they all got an empty xmls-attribute (<url xmlns="">...</url>), unless I specified the namespace when I create the element in the template.

It's not very DRY. is there a way to define the namespace of alle elements that are created?

<xsl:template match="/">
    <!-- Root element has a namespace -->
    <urlset xmlns=""&gt;

<xsl:template match="Document">
    <!-- Do it this way to prevent empty xmlns attribute on element -->
    <xsl:element name="url" namespace=""&gt;
        <!-- This element will get the empty xmlns attribute, unless I create it like the url element -->
            <xsl:value-of select="Path" />
        <!-- There are more elements to create here, do I have to specify the namespace each time? -->


+2  A: 

Specify the default namespace on the root of the stylesheet.

<xsl:stylesheet version="1.0" xmlns="" xmlns:xsl=""&gt;

Or, in my opinion a preferred solution, define a prefix on the root and use it later for your elements:

<xsl:stylesheet version="1.0" xmlns:sm="" xmlns:xsl=""&gt;
    <xsl:template match="/">
Doh! That simple. I prefer the first solution. Thanks!
The first solution has the drawback of giving you trouble in XPath queries if you need to use the empty namespace, and it also prevents you from creating fully qualified attributes. Also, it may be more confusing for the reader because the prefix helps associate the element to the correct namespace when reading, especially in documents with several namespaces. That said, the solutions are pretty much equivalent, and you can control the output of the `xmlns` attributes via `exclude-result-prefixes` attribute on the stylesheet and the `xsl:namespace-alias` element.