XSLT <xsl:namespace-alias> element
Definition and Usage
The <xsl:namespace-alias> element is used to replace the namespace in the stylesheet with a different namespace in the output, in other words, using another prefix to replace the prefix associated with the given namespace.
Note:The <xsl:namespace-alias> is a top-level element (top-level element) and must be a child element of <xsl:stylesheet> or <xsl:transform>.
Sometimes, an XSLT file generates another XSLT. This brings up a problem with namespaces because there is no clear way to declare two prefixes for the same namespace, and the processor will not treat the two prefixes as the same namespace and operate on them. The <xsl:namespace-alias> command can assign a transitional namespace to an alternative prefix, apply the stylesheet, and then map the alternative namespace to the XSLT namespace.
Although the file generation from XSL to XSL is the main purpose of this command, it is not the only purpose. This command can be used anywhere there is a namespace conflict (for example, xsi: schema data type namespace).
Syntax
<xsl:namespace-alias stylesheet-prefix="prefix|#default" result-prefix="prefix|"#default"/>
Attribute
Attribute | Value | Description |
---|---|---|
stylesheet-prefix |
|
Required. Specifies the namespace you want to change. |
result-prefix |
|
Required. Specifies the expected namespace for the output. |
Instance
Example 1
The prefix wxsl is converted to the prefix xsl: in the output:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:wxsl="http://www.codew3c.com/w3style.xsl"> <xsl:namespace-alias stylesheet-prefix="wxsl" result-prefix="xsl"/> <xsl:template match="/"> <wxsl:stylesheet> <xsl:apply-templates/> </wxsl:stylesheet> </xsl:template> </xsl:stylesheet>