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="http://www.sitemaps.org/schemas/sitemap/0.9">
<xsl:apply-templates/>
</urlset>
</xsl:template>
<xsl:template match="Document">
<!-- Do it this way to prevent empty xmlns attribute on element -->
<xsl:element name="url" namespace="http://www.sitemaps.org/schemas/sitemap/0.9">
<!-- This element will get the empty xmlns attribute, unless I create it like the url element -->
<location>
<xsl:value-of select="Path" />
</location>
<!-- There are more elements to create here, do I have to specify the namespace each time? -->
</xsl:element>
</xsl:template>
Thanks!