Automatic transformation of XML namespaces/Transformations/Order kinds of transformers
For up-down and down-up transformer (see below) we first we select primary nodes from the set of document nodes.
An element is having a certain namespace, if it is either an element of this namespace or has an attribute of this namespace.
Rationale: This twist about namespaced attributes is useful for such usages as XLink. Example:
may transform into
<a xmlns="http://www.w3.org/1999/xhtml" href="http://www.w3.org/1999/xlink"><myElement>...</myElement></a>.
In this example the link is “raised”, above the element it is applied to, to a “wrapper” element (<a> in this example).
Next stage, feed every primary node, having a namespace which is a source namespace of the transformer, to the transformer. This constructs a new document.
After this the stage is repeated.
Note: This facilitates for example embedding a complete XHTML document into our XML. The document transformer will receive only the root of the XHTML not its fragments which it may not understand.
The entire document transformer
The entire document transformer is just applying once the transformer to the entire document.
The transformer is applied to the first element having the source NS. After this the step is repeated until there are no elements of the source namespace.
Note for implementers: You can start searching for the next element from the point fed to the last transformer.
It should give a warning (or error?) if the head element of the transformed subtree remains with the same namespace. May we skip to the next element in order to avoid an infinite loop?
Find all elements of the source NS which are not descendants of an element of the source NS.
Run the transformer for every subtree designated by these elements.
Repeat these steps until there are no elements of the source namespace.
Find all primary elements which have no primary descendants. Transform every subtree designated by these elements.
Then find the set of primary elements which are the first primary ancestor of these elements, and replace the set of elements in consideration with these elements.
Repeat the steps until the set it empty.