Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
If you write a stylesheet that produces an XSLT stylesheet as its output, then it becomes very important to get the right namespace declarations into the output, because XSLT makes heavy use of attributes that contain namespace prefixes: they arise both in attributes such as the
name
attribute of
name
attributes that appear to have QName-valued content do not actually have a type of
xs:QName
. This is because although their lexical space is the same as
xs:QName
, they follow the convention “no prefix means no namespace”, whereas the rule for the
xs:QName
type is “no prefix means default namespace”. So these attributes are simply strings, which means it is the application that must choose a namespace prefix and then create a namespace node to bind this to the correct namespace URI.
The
Namespace fixup happens after all the namespace nodes from this result sequence have been constructed, and it is constrained to generate prefixes that don't clash with these namespace nodes. If you have created a namespace node for the default namespace (that is, the empty prefix), then the system will have a problem if the element node itself is in the null namespace, because an element in the null namespace has to use the empty prefix, and it will no longer be available. This can cause a runtime failure.
See Also
xsl:namespace-alias
The
Changes in 2.0
The rules for generating namespace prefixes have been made stricter. The “null namespace” is now treated in the same way as a real namespace (many XSLT 1.0 products did this, but the specification wasn't clear).
Format
stylesheet-prefix = prefix | “#default”
result-prefix = prefix | “#default”/>
Position
Attributes
Name | Value | Meaning |
stylesheet-prefix mandatory | NCName or #default | A namespace prefix used in the stylesheet |
result-prefix mandatory | NCName or #default | The prefix of the corresponding namespace to be used in the output |
Content
None. The
Effect
The
Normally, when an element node is output by processing a literal result element, the output element name will have the same local part, the same prefix, and the same namespace URI as those of the literal result element itself. The same applies to the attributes of the literal result element. The namespace nodes on the literal result element must be copied unchanged to the result tree, using the same prefix and namespace URI. (The XSLT specification states that when processing a literal result element, all the namespaces that are in scope for the element in the stylesheet, with certain defined exceptions, will also be present in the output, even if they aren't used. Redundant namespace nodes can be suppressed by using the
xsl:exclude-result-prefixes
attribute. For more details on this, see the section
Literal Result Elements
, on page 112 in Chapter 3.)
Suppose you want the output document to be an XSLT stylesheet. Then you need to create elements such as
The answer is to use a different namespace on the literal result element in the stylesheet, and include an
out
should be mapped to the result prefix
xsl
.
The
#default
. If there is no default namespace defined,
#default
denotes the “null namespace URI”, which for this purpose is treated as if it were an ordinary namespace.