From 6abd82e468c28c8e3872dbef2beafe183f1b2983 Mon Sep 17 00:00:00 2001 From: Michael Kay Date: Fri, 12 May 2023 12:51:34 +0100 Subject: [PATCH] Revised design taking comments into account --- .../xslt-40/src/element-catalog.xml | 12 +- specifications/xslt-40/src/xslt.xml | 202 +++++++++++------- 2 files changed, 135 insertions(+), 79 deletions(-) diff --git a/specifications/xslt-40/src/element-catalog.xml b/specifications/xslt-40/src/element-catalog.xml index 597fefd29..17f3ab90c 100644 --- a/specifications/xslt-40/src/element-catalog.xml +++ b/specifications/xslt-40/src/element-catalog.xml @@ -55,8 +55,8 @@ - - + + @@ -197,8 +197,8 @@ - - + + @@ -252,8 +252,8 @@ - - + + diff --git a/specifications/xslt-40/src/xslt.xml b/specifications/xslt-40/src/xslt.xml index 8a07e35db..2725ab97a 100644 --- a/specifications/xslt-40/src/xslt.xml +++ b/specifications/xslt-40/src/xslt.xml @@ -2856,10 +2856,10 @@

The fixed namespace bindings for a are - established using the fixed-prefixes attribute on the xsl:stylesheet, + established using the fixed-namespaces attribute on the xsl:stylesheet, xsl:transform, or xsl:package element enclosing the stylesheet module.

-

For example, the attribute fixed-prefixes="math map array" +

For example, the attribute fixed-namespaces="math map array" establishes bindings for the prefixes math, map, and array to the namespace URIs conventionally associated with these prefixes as described in .

@@ -2877,12 +2877,12 @@

The applicable static namespaces for an element in a stylesheet module are the for the module if the root element - of the module has a fixed-prefixes attribute, or the + of the module has a fixed-namespaces attribute, or the of the element otherwise.

The effect of declaring fixed namespace bindings is described in more detail in - .

+ .

XSLT Namespace

@@ -6630,17 +6630,16 @@ and version="1.0" otherwise.

- - The fixed-prefixes Attribute -

The fixed-prefixes attribute is a whitespace-separated list of namespace - prefixes (in the form of NCNames) that together define the + + The fixed-namespaces Attribute +

The fixed-namespaces attribute, if present, defines the for a . The attribute may appear only on the outermost element of a stylesheet module (xsl:stylesheet, xsl:transform, or xsl:package). It is not available with simplified stylesheet modules.

-

If the fixed-prefixes attribute is present, then it defines the entire +

If the fixed-namespaces attribute is present, then it defines the entire set of namespace bindings present in the static context of XPath expressions and patterns within the stylesheet, as well as other constructs where namespace prefixes are used in attribute and text nodes, @@ -6648,88 +6647,145 @@ and version="1.0" otherwise.

and xsl:variable, and as and type attributes referring to item types and schema types.

-

Each name listed in the fixed-prefixes attribute must - be one of the following:

+

The value of the attribute is a whitespace-separated list of tokens, where each token + contributes one or more namespace bindings to the + of the . Each token must be one of the following. If + a token falls into more than one of these categories, then the first one that applies + takes precedence.

+ + +

The string #standard, which is equivalent to specifying + xsl xml xs xsi fn math map array err. This has the effect of binding + each of these namespace prefixes to the with which + it is conventionally associated.

+

An NCName corresponding to one of the namespace prefixes present + in the in-scope namespaces of the containing element node. This has the effect of adding + the corresponding namespace binding to the .

+

Any one of the strings xsl, xml, + xs, xsi, fn, math, + map, array, err. This has the effect of binding + that particular namespace prefix to the with which + it is conventionally associated, whether or not the + contain a binding for this prefix.

+

Including xml in the list has no effect, since the XML namespace + will always be in scope anyway.

+
+

A string in the form prefix=uri, where prefix is an NCName + and uri is a (non-empty) namespace URI: for example, + xalan=http://xml.apache.org/xalan. This has the effect of binding the specified + prefix to the specified URI.

+
+

A identifying the location of an + XML document whose namespace bindings are to be used. For example, ./package.xsl. + A token is interpreted as a URI if it does not match any of the other possibilities listed above + (which will be the case if it contains a "/" as in this example).

+

The is used to locate an XML document, in the same way + as described for xsl:include and xsl:import in + . The resource that is retrieved may be any namespace well-formed + XML document. The in-scope namespace bindings of the outermost element of this document are + added to the of the stylesheet module.

+
+
+ +

If different tokens in the fixed-namespaces attribute result in multiple bindings + for the same namespace prefix, the last one wins.

+ - -

A namespace prefix that is bound to a URI in one of the namespace nodes - of the containing element.

-

A namespace prefix that is bound to a URI in the - - of the importing or including stylesheet module.

-

One of the conventional prefixes associated with a - : xsl, xml, - xs, xsi, fn, math, - map, array, err.

-

-

It is a static error if a prefix - appearing in the fixed-prefixes attribute is not - bound to a namespace in either the in-scope namespaces of the containing element node - or the of the including or importing - stylesheet module, and is not one of the conventional prefixes associated - with a .

+

It is a static error if a token + appearing in the fixed-namespaces attribute takes a form + that is not one of the permitted forms, or if it interpreted as a URI + but cannot be dereferenced to locate a namespace well-formed XML document. + It is not permitted to bind the prefix xmlns. It is not permitted to bind the + prefix xml or the XML namespace URI http://www.w3.org/XML/1998/namespace, other than + to each other.

-

If a name satisfies more than one of these roles, then the relevant namespace URI - is taken from the first of these that applies: for example if the prefix f - is bound using the namespace declaration xmlns:f="http://example.com/foo" - on the containing xsl:stylesheeet element, but is associated - with the namespace http://example.com/bar in the importing module, - then the binding in this module is to xmlns:f="http://example.com/foo".

- -

A namespace URI that is bound to a prefix listed in the fixed-prefixes - attribute automatically becomes an excluded namespace - (see ). This means that the namespace binding will - not be added to elements created literal result elements - unless they are actually needed for the names of constructed elements and attributes.

- -

The following observations apply when a fixed-prefixes attribute is present:

+

The following observations apply when a fixed-namespaces attribute is present:

-

All expressions in the stylesheet module have the same +

All expressions in the stylesheet module will have the same statically known - namespaces in their static context, namely the - bindings of the prefixes listed in the fixed-prefixes - attribute. This means that all prefixes used in XPath expressions, patterns, + namespaces in their static context. This means that all + prefixes used in XPath expressions, patterns, and similar constructs must be declared at the top level.

-

This constraint may have performance benefits, especially since - the statically known - namespaces for each expression need to be retained - at evaluation time for the few constructs that use the information dynamically, - for example casting to xs:QName.

+

Namespace prefixes used in element and attribute names in the stylesheet - cannot be declared using this mechanism.

-

When a stylesheet module M imports or includes a stylesheet - module N, the - of M are inherited by N to the extent that the relevant - namespace prefixes are listed in the fixed-prefixes attribute - of N, and are not bound to a different namespace.

+ cannot be declared using this mechanism. Such prefixes must be bound using + . This also applies to namespace + prefixes used in the [xsl:]exclude-result-prefixes + and [xsl:]extension-element-prefixes attributes, and the + stylesheet-prefix and result-prefix attributes + of xsl:namespace-alias.

+

It is not an error for an element within a stylesheet module - to rebind a prefix listed in the fixed-prefixes attribute + to rebind a prefix listed in the fixed-namespaces attribute to a different URI; however this rebinding has no effect on the static context of XPath expressions and other similar constructs within its scope.

-

The fixed-prefixes attribute has no effect on the interpretation +

The fixed-namespaces attribute has no effect on the interpretation of unprefixed names.

-

Some of the benefits of using the fixed-prefixes attribute are:

+

The design decision to declare in an attribute + of the xsl:stylesheet element, rather than in + declarations, is motivated (a) by the desire to ensure + that the namespace bindings are uniform across the entire stylesheet module, and (b) by the + need for namespace bindings to be declared before they are used, which is necessary (for example) to + allow them to be used in [xsl:]use-when expressions. It is possible to use + the in other attributes of the xsl:stylesheet + element, such as default-mode. It is also possible to use them in + shadow attributes (see ).

+

It is possible for the fixed-namespaces attribute itself to be supplied as + a shadow attribute (written with an underscore, _fixed-namespaces). Note that + it can then refer to static variables + declared in an importing or including . This provides an + alternative way of sharing common namespace bindings throughout a .

+
+ +

The ability to fetch namespace bindings using a URI can be exploited in various ways:

+ +

Generally, the benefit is that it avoids repeating the same information + in every stylesheet module, thereby reducing the amount of boilerplate code and keeping + common information in a common place. This satisfies the DRY principle in software + engineering: Don't Repeat Yourself.

+

The document identified by the URI may be a stylesheet module. + One way to use the feature is to use the + as the primary source for namespace bindings.

+

It is also possible to adopt the namespace bindings from a sample source + document. For example, if it is known that the stylesheet is designed primarily to process + documents whose first start tag takes the form:

+ ]]> +

then these three namespace bindings may conveniently be copied to the stylesheet + by referencing a sample document of this form.

+

Note however, that only the namespace bindings from the outermost element of + the document will be copied.

+

It is possible to supply multiple URIs to assemble namespace bindings + from more than one source.

+

Namespace bindings taken from an external document may be overridden + using a local declaration for the prefix. This must appear after the URI + in the content of the fixed-namespaces attribute.

+
+
+ +

Using the fixed-namespaces attribute rather than + to bind namespaces has potential benefits:

-

Reducing the amount of "boilerplate" code at the top of every stylesheet - module: there is no need to list the URIs associated with conventional prefixes - such as the xs and map namespaces, and namespace bindings - that are wanted in every module of a stylesheet can be defined once in the top-level - stylesheet module.

-

Reducing the overhead in executable stylesheet code of maintaining different - namespace contexts for every expression, especially since the namespace context is - needed, but rarely used, at evaluation time.

-

Ability to separate namespace declarations used for elements and attributes - in the result tree from those used to access nodes in source trees and constructs - in the stylesheet.

+

It reduces repetitive coding across stylesheet module boundaries, + and thus eliminates a source of potential errors.

+

It ensures that all expressions in a stylesheet module have the same + namespace bindings in their static context. This can reduce implementation overheads + because it prevents the need to maintain the namespace context at the level of individual + expressions through rewrites such as function inlining. With processors that compile + stylesheets to a persistent executable form, it can contribute to a reduction in + the size of compiled code.

+

Namespaces bound in this way will never accidentally leak into a result tree.

TODO: This is a first step. We hope to propose further changes that reduce the @@ -9239,9 +9295,9 @@ and version="1.0" otherwise.

reserved namespaces are those listed below.

Each of the reserved namespaces has a conventional - prefix. As described in , the fixed-prefixes + prefix. As described in , the fixed-namespaces attribute may bind one of the reserved namespaces simply by referring to its conventional - prefix. For example, fixed-prefixes="xs" has the effect of binding the prefix + prefix. For example, fixed-namespaces="xs" has the effect of binding the prefix xs to the namespace http://www.w3.org/2001/XMLSchema.