Setting a default namespace with a direct element constructor is straightforward. Ex:
<map xmlns="http://www.w3.org/2013/XSL/json"/>
The above direct constructor outputs the exact same element, as expected. However, if I try to do the same with computed element and namespace constructors, I'm out of luck:
element {"map"} {
namespace {""} { "http://www.w3.org/2013/XSL/json" }
}
The above throws a Duplicate namespace declaration: '' error in BaseX 8.2; and a XTDE0440: Cannot output a namespace node for the default namespace when the element is in no namespace in Saxon-HE 9.6.
There's no problem if I pass a prefix. The following works well:
element {"map"} {
namespace { "e" } {"http://www.w3.org/2013/XSL/json"}
}
In the above case, neither BaseX nor Saxon complain. But I want to set the namespace as the default namespace.
Regarding computed namespace constructors, the XQuery 3.0 spec says:
If the constructor specifies a PrefixExpr, the prefix expression is evaluated as follows:
b. If the result is the empty sequence or a zero-length xs:string or xs:untypedAtomic value, the new namespace node has no name (such a namespace node represents a binding for the default namespace).
The spec also provides a similar example of a "computed namespace constructor with an empty prefix":
namespace { "" } {"http://a.example.com" }
Why then, the error messages? Apparently, the computed namespace constructor tries to re-declare a namespace already declared by the computed element constructor. On the other hand, the direct constructor would be directly initializing the element's namespace to my choice. But this is just my guess. My only certainty is my puzzlement.
In any case, is there a way to obtain with computed constructors the same result achievable with the direct constructor?