This documentation is archived and is not being maintained.

Example of <xsl:namespace-alias>

This example demonstrates how to use <xsl:namespace-alias> to declare the alt: prefix as an alias for the XSLT namespace in the literal result tree, when the xsl: prefix is bound for the same namespace URI in the stylesheet. The output is another XSLT style sheet.

<?xml version='1.0'?>
<?xml-stylesheet type="text/xsl" href="alias.xsl"?>

<?xml version='1.0'?>
<xsl:stylesheet version="1.0"

<xsl:namespace-alias stylesheet-prefix="alt" result-prefix="xsl"/>
<xsl:param name="browser" select="'InternetExplorer'"/>

<xsl:template match="/">
         <xsl:when test="$browser='InternetExplorer'">
            <alt:import href="IERoutines.xsl"/>
            <alt:template match="/">
                  <alt:call-template name="showTable"/>
            <alt:import href="OtherBrowserRoutines.xsl"/>
            <alt:template match="/">
                  <alt:call-template name="showTable"/>

var xmldoc = new ActiveXObject("Msxml2.DOMDocument.6.0");

var xsldoc= new ActiveXObject("Msxml2.DOMDocument.6.0");
xsldoc.async = false;

var outfile = new ActiveXObject("Msxml2.DOMDocument.6.0");

var strResult;
strResult = xmldoc.transformNode(xsldoc);

WScript.Echo("Output.xsl was made.");

Try It!

  1. Copy the XML file above and paste it into a text file. Save the file as mymin.xml to a directory on your local drive.

  2. Copy the XSLT file above and paste it into a text file. Save the file as alias.xsl in the same directory.

  3. Copy the JScript listing above, and paste it into a text file. Save the file as test.js, in the same directory.

  4. Double click the test.js file from Windows Explorer to launch the application. Alternatively, you can type "test.js" from a command prompt.


    Under operating systems other than Windows 2000 or Windows XP, you might need to install Windows Scripting Host (wscript.exe), if it is not already installed.

    The following output file, output.xsl, appears on your local drive.

  5. Verify that your output is the same as that listed below.

When you run test.js, you should see the following output in a message box or console window:

Output.xsl was made.

The processor also outputs the following stream as an XSLT file, output.xsl, into the folder where you stored the sample files. White space has been added here for clarity.

<?xml version="1.0" encoding="UTF-16"?>
<xsl:import href="IERoutines.xsl" />

<xsl:template match="/">
      <xsl:call-template name="showTable" />