<xsl:namespace-alias> |
Allows you to define an alias for a namespace when using the namespace directly would complicate processing. This seldom-used element is the simplest way to write a stylesheet that generates another stylesheet.
Category
Top-level element
Required Attributes

stylesheet-prefix
  Defines the prefix used in the stylesheet to refer to the namespace.

result-prefix
  Defines the prefix for the namespace referred to by the alias. This prefix must be declared in the stylesheet, regardless of whether any elements in the stylesheet use it.

Optional Attributes
None.
Content
None. <xsl:namespace-alias> is an empty element.
Appears in
<xsl:stylesheet>. <xsl:namespace-alias> is a top-level element and can appear only as a child of <xsl:stylesheet>.
Defined in
XSLT section 7.1.1, Literal Result Elements.
Example
This element is not used frequently, and the reasons for its existence are based on the somewhat obscure case of an XSLT stylesheet that needs to generate another XSLT stylesheet. Our test case here creates a stylesheet that generates the identity transform, a stylesheet that simply copies any input document to the result tree. Here's our original stylesheet that uses the namespace alias:
    <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xslout="(the namespace URI doesn't matter here)">

      <xsl:output method="xml" indent="yes"/>

      <xsl:namespace-alias stylesheet-prefix="xslout"
        result-prefix="xsl"/>

      <xsl:template match="/">
        <xslout:stylesheet version="1.0">
          <xslout:output method="xml"/>
          <xslout:template match="/">
            <xslout:copy-of select="."/>
          </xslout:template>
        </xslout:stylesheet>
      </xsl:template>

    </xsl:stylesheet>
When we run this stylesheet with any XML document at all, we get a new stylesheet:
    <?xml version="1.0" encoding="UTF-8"?>
    <xslout:stylesheet xmlns:xslout="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
    <xslout:output method="xml"/>
    <xslout:template match="/">
    <xslout:copy-of select="."/>
    </xslout:template>
    </xslout:stylesheet>
You can take this generated stylesheet and use it to copy any XML document. In our original stylesheet, we use an <xsl:namespace-alias> because we have no other way of identifying to the XSLT processor with which XSLT elements should be processed and which ones should be treated as literals passed to the output. Using the namespace alias lets us generate the XSLT elements we need in our output. Notice in the result document that the correct namespace value was declared automatically on the <xslout:stylesheet> element.