I can do it, but not for the default namespace, using the <xsl:namespace>.
If I try to do it for the default namespace:
<xsl:namespace name="" select"myUri"/>
it never works. It demands that I explicitly define the namespace of the element to be able to use the above null prefix declaration.
The reason I want this is because I have a task to transform an input XML file to another output xml. The output XML has many elements and i dont want to have to explicitly set the namespace for every element. Thats why I want to set the default and never bother again. But the default must be computed from some data in the source XML. It does not change during the whole transformation, but it is dependent on input XML data.
Any solution?
EDIT 1: To sup up:
- I want to create a namespace dynamically and set it to be the default namespace of the output xml document. The uri of the namespace is derived from some data in the input XML.
- If I use
<xsl:namespace>
in my root output element, I cannot create a default namespace for it, only a prefixed one. And even with the prefixed one, it does not propagate to children.
EDIT 2: dkackman proposed:
<xsl:template match="root">
<xsl:param name ="ns">my-computed-namespace</xsl:param>
<xsl:element name="newRoot" namespace="{$ns}"/>
</xsl:template>
It almost solves the problem. Unfortunately the children are injected with ""(blank) namespace by the transformer. Here is what I get if I put a child element:
<newRoot xmlns="my-computed-namespace">
<child xmlns=""> ...
</child>
</newRoot>
Why does the transformer put this xmlns=""
in the children? If I can prevent this then I have found my solution.