Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The prefix, as always, is simply a way of referring to the associated namespace URI: it is the namespace URI that is really being excluded, not the prefix itself. So if the same namespace URI is declared again with a different prefix, it is still an excluded namespace.
What exclude-result-prefixes Doesn't Do
The
[xsl:]exclude-result-prefixes
attribute applies only to namespace nodes copied from the stylesheet using literal result elements. It does not affect namespace nodes copied from the source document using
copy-namespaces
attribute on the instruction itself.
Like the other attributes on the
exclude-result-prefixes
attribute applies only to elements actually within the stylesheet module, not to those brought in using
What happens if you try to exclude a namespace that is actually needed because it is used in the result tree? The XSLT processor is obliged to generate output that conforms to the Namespaces Recommendation, so it will ignore the request to exclude this namespace. Or more accurately, the evaluation of the literal result element will not cause the namespace node to be copied, but the namespace fixup process that comes into play when the element has been constructed will then generate namespace nodes for any namespaces that were missing. Namespace fixup is described under
Using
exclude-result-prefixes
will never move an element or attribute into a different namespace. People sometimes see an element such as
xmlns=“”
. The answer is: look at the code that's generating the
xmlns=“”
declaration.
Usage
The simplest way to decide which namespace prefixes to list here is by trial and error. Run the stylesheet, and if the output document contains namespace declarations that clearly serve no useful purpose, add them to the
exclude-result-prefixes
attribute and run the stylesheet again.
The XSLT namespace itself and namespaces used for extension elements will be excluded automatically. However, the stylesheet is also likely to contain references to the schema namespace, which you may not want in your result document. It will also contain any namespace you have used for defining your local stylesheet functions, which you almost certainly don't want in the result document.
A common cause of unwanted namespace declarations finding their way into the result document is where your stylesheet needs to refer to namespaces used in the source document; for example, in a template
match
pattern, but where none of these elements is copied into the destination document.
For example:
version=“2.0”
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform”
xmlns:po=“http://accounting.org/xslt”
exclude-result-prefixes=“po”
>
…
Here the
po
namespace would be copied into the result document if it weren't for the
exclude- result-prefixes
attribute, because it is in scope when the literal result element
As with the other
xsl:exclude-result-prefixes
attribute on any literal result element. It's probably a good idea in practice to keep the declaration of a namespace and the directive that excludes it from the result document together in one place.
The extension-element-prefixes Attribute
This attribute identifies a set of namespaces used for extension instructions. Extension instructions may be defined by an implementor, a user, or a third party. An example is the
[xsl:]extension-element-prefixes
attribute of the containing
Effect
The value of the attribute is a whitespace-separated list of prefixes; each of these prefixes must identify a namespace declaration present on the containing element. The default namespace (the namespace declared using the
xmlns
attribute) may be designated as an extension element namespace by using the pseudoprefix
#default
.
The scope of the
extension-element-prefixes
attribute is the stylesheet module. It does not affect included or imported modules.
If a namespace is designated as an extension element namespace, then every XSLT processor will recognize that these elements are extension instructions. However, some XSLT processors may be unable to evaluate them. For example, if the namespace
http://saxon.sf.net/
is designated as an extension namespace, then both Saxon and AltovaXML will recognize that these elements are extensions, but the likelihood is that Saxon will know how to handle them and AltovaXML won't. If the processor knows how to evaluate the instruction, it does so; otherwise, it looks to see if the element contains an