fixed-namespaces - a clarification

I stumbled slightly when presenting the fixed-namespaces proposal on the question of access to namespace bindings at runtime.

If the fixed-namespaces attribute is present, then the namespaces thereby declared become part of the static context for XPath expressions in the module, and as such, they are present for constructs that make use of the static context at run time; for example, casting of strings to QNames. The main benefit of using fixed-namespaces from this point of view is that there are likely to be far fewer different combinations of namespaces in use for different parts of the stylesheet, and knowing which module an expression appeared in will generally be sufficient to identify its in-scope namespaces. There is therefore less need for the executable code to contain fine-grained information about changes in namespace context.

The rule for literal result elements is that the constructed element will have a copy of the namespace nodes that were present on the element node in the stylesheet tree, unless excluded. Only native namespace declarations count; this is not affected by the fixed-namespaces attribute. The practical consequence is that if the new attribute is always used to declare namespaces needed for purposes such as function names, then it is not necessary to use exclude-result-prefixes to prevent them polluting the result tree. Namespace aliasing, which is relevant only to literal result elements, applies only to native namespace declarations and is unaffected by the fixed-namespaces attribute.

Some points that users may need to be aware of:

* The "xsl" prefix is primarily used for XML element names such as xsl:value-of (and occasionally, XML attribute names). It is also occasionally used within XPath expressions and other contexts where the fixed-namespaces apply, for example (a) in arguments to fn:system-property(), and (b) in the names `xsl:original` and `xsl:initial-template`. It will therefore usually be appropriate to declare the xsl prefix both in a native namespace declaration, and in fixed-namespaces.

* In xsl:element and xsl:attribute, the prefix part of the `name` attribute is bound using the fixed-namespaces where defined; not using the native namespace declarations.

* in fact, there's a nearly-universal rule that when prefixes appear in XML element and attribute names, they are governed by the native namespace declarations, but when they appear in the content of attributes and text nodes, they are governed by the fixed-namespace bindings. The exceptions I know of (to the second part of this rule) are prefixes used in the extension-element-prefixes and exclude-result-prefixes attributes, and in the stylesheet-prefix and result-prefix attributes of xsl:namespace-alias.

I will add notes to draw out some of these points in a final revision of the PR.

Michael Kay
Saxonica

Received on Tuesday, 28 November 2023 19:18:34 UTC