<html>
<head>
<title>&lt;xsl:namespace-alias&gt;</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div id="Description">
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
<tr>
<td valign="top" class="NAME">&lt;xsl:namespace-alias&gt;</td>
<td valign="top" class="COMPATIBILITY">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
</tr>
<tr>
<td valign="top" colspan="2" class="description">
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.</td></tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Category</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>Top-level element</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Required Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<dl>
<dt>
stylesheet-prefix
</dt>
<dd>
Defines the prefix used in the stylesheet to refer to the namespace.
<P></p>
<dt>
result-prefix
</dt>
<dd>
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.
<P></p>
</dl>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Optional Attributes</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Content</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>None. <span class="LITERAL">&lt;xsl:namespace-alias&gt;</span> is an empty element. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Appears in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>
<span class="LITERAL">&lt;xsl:stylesheet&gt;</span>. <span class="LITERAL">&lt;xsl:namespace-alias&gt;</span> is a top-level element and can appear only as a child of <span class="LITERAL">&lt;xsl:stylesheet&gt;</span>.</p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Defined in</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>XSLT section 7.1.1, Literal Result Elements. </p>
</td>
</tr>
<tr>
<td colspan="2" class="CLEARSEPARATION">&nbsp;</td>
</tr>
<tr>
<td colspan="2" class="TITLE">Example</td>
</tr>
<tr>
<td colspan="2" class="description">
<p>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:</p>
<span class="PROGRAMLISTING"><pre>
&lt;xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xslout="(the namespace URI doesn't matter here)"&gt;

  &lt;xsl:output method="xml" indent="yes"/&gt;
 
  &lt;xsl:namespace-alias stylesheet-prefix="xslout"
    result-prefix="xsl"/&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xslout:stylesheet version="1.0"&gt;
      &lt;xslout:output method="xml"/&gt;
      &lt;xslout:template match="/"&gt;
        &lt;xslout:copy-of select="."/&gt;
      &lt;/xslout:template&gt;
    &lt;/xslout:stylesheet&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre></span>
<p>When we run this stylesheet with any XML document at all, we get a new stylesheet:</p>
<span class="PROGRAMLISTING"><pre>
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;xslout:stylesheet xmlns:xslout="http://www.w3.org/1999/XSL/Transform" 
  version="1.0"&gt;
&lt;xslout:output method="xml"/&gt;
&lt;xslout:template match="/"&gt;
&lt;xslout:copy-of select="."/&gt;
&lt;/xslout:template&gt;
&lt;/xslout:stylesheet&gt;</pre></span>
<p>You can take this generated stylesheet and use it to copy any XML document. In our original stylesheet, we use an <span class="LITERAL">&lt;xsl:namespace-alias&gt;</span> 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 <span class="LITERAL">&lt;xslout:stylesheet&gt;</span> element. </p>
</td>
</tr>
</table>
</div>
</body>
</html>