Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The
result-prefix
attribute (or no prefix, if this is specified as
#default
).
The substitution of one namespace URI for another affects the names of literal result elements themselves, and the names of all attributes of literal result elements. It also affects the URIs of namespace nodes copied into the result tree from a literal result element. It does not affect elements created using
There was often confusion among XSLT 1.0 users about what namespaces they should expect to find declared in the result document, and different processors handled this differently. In XSLT 2.0, the rules have been clarified. Namespaces find their way from the stylesheet into the result document whenever a literal result element is evaluated. XSLT 2.0 states clearly that if the literal result element has a namespace node with the URI associated with the
stylesheet-prefix
of an
result-prefix
of an
http://www.w3.org/1999/XSL/Transform
that would normally not be copied. These rules are designed to produce the result that most users would expect: a literal result element
xsl
namespace will be declared in the result document, and the
out
namespace will not be declared.
If there are several
stylesheet-prefix
, the one with highest import precedence is used; a compile-time error is reported if there is more than one at the highest import precedence.
The aliasing of namespace URIs applies at the point when a literal result element in the stylesheet is evaluated to create an element node in a result sequence. It applies whether or not this element is written to a final result tree. This means that if you examine a temporary document into which literal result elements have been copied, the corresponding elements and attributes will use the namespace URI associated with the result prefix, not the stylesheet prefix.
Aliasing of namespaces happens before the namespace fixup process described under
Usage and Examples
The main justification for this facility is to enable stylesheets to be written that generate stylesheets as output. This is not as improbable a scenario as it sounds; there are many possible reasons for using such applications (sometimes referred to as
meta-stylesheets
), including the following:
In fact, having gone through all the trouble of defining XSLT stylesheets as well-formed XML documents, it would be very surprising if it were impossible to manipulate them using XSLT itself.
However, it is possible to create stylesheets as output without recourse to
There may be other situations where
Aliasing the XML Namespace
It's possible to define an alias for the
xml
namespace. For example, the following stylesheet (
xml-space.xsl
):
xmlns:xsl=“http://www.w3.org/1999/XSL/Transform” version=“2.0”
xmlns:axml=“alias”>
produces the following output:
This is useful because it gets an
xml:space=“preserve”
attribute into the result document without affecting the way that whitespace is handled in the stylesheet.