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 File (mymin.xml)
<?xml version='1.0'?> <?xml-stylesheet type="text/xsl" href="alias.xsl"?> <myelem/>
XSLT File (alias.xsl)
<?xml version='1.0'?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:alt="http://www.w3.org/1999/XSL/Transform-alternate"> <xsl:namespace-alias stylesheet-prefix="alt" result-prefix="xsl"/> <xsl:param name="browser" select="'InternetExplorer'"/> <xsl:template match="/"> <alt:stylesheet> <xsl:choose> <xsl:when test="$browser='InternetExplorer'"> <alt:import href="IERoutines.xsl"/> <alt:template match="/"> <div> <alt:call-template name="showTable"/> </div> </alt:template> </xsl:when> <xsl:otherwise> <alt:import href="OtherBrowserRoutines.xsl"/> <alt:template match="/"> <div> <alt:call-template name="showTable"/> </div> </alt:template> </xsl:otherwise> </xsl:choose> </alt:stylesheet> </xsl:template> </xsl:stylesheet>
JScript file (test.js)
var xmldoc = new ActiveXObject("Msxml2.DOMDocument.5.0"); xmldoc.async=false; xmldoc.load("mymin.xml"); var xsldoc= new ActiveXObject("Msxml2.DOMDocument.5.0"); xsldoc.async = false; xsldoc.load("alias.xsl"); var outfile = new ActiveXObject("Msxml2.DOMDocument.5.0"); outfile.async=false; var strResult; strResult = xmldoc.transformNode(xsldoc); outfile.loadXML(strResult); outfile.save("output.xsl"); WScript.Echo("Output.xsl was made.");
Try It!
Note 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.
Output
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:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:import href="IERoutines.xsl" /> <xsl:template match="/"> <div> <xsl:call-template name="showTable" /> </div> </xsl:template> </xsl:stylesheet>
<xsl:import> Element | <xsl:include> Element