Question

I saw a lot of posts online about MSXML4 to 6 or XSLT 1.0 versus 2.0 etc. But they could not answer my question.

I have a XSLT transformation code that works with MSXML4 APIs (XSLTransform and FreeThreadedDomDocument) on IE7 via Javascript.

Same code doesnt work with with MSXML6 APIs (XSLTransform and DomDocument) on IE9 via Javascript. It throws this error

"Namespace 'urn:mynamespace:mytable:transactions' does not contain any functions"

I have made sure that my ActiveX are enabled for MSXML4 and 6 both on IE9. Below is the code of the main tranformer XSLT, the reference XSLT & the JS code ...

Core XSLT: functions.xsl

<xsl:stylesheet version="1.0" 
               xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
               xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
               xmlns:myfuncs="urn:mynamespace:mytable:transactions" >

<msxsl:script language="javascript" implements-prefix="myfuncs">

<![CDATA[
// convert system GMT time into local time
// usage: <xsl:value-of select="myfuncs:localDateTime(datetime)"/>

var openBalance = 0;

function setOpenBalance(openBal)
{
    openBalance = openBal;
}

function getOpenBalance()
{
    openBalance = openBal;
    return openBalance ;
}
]]>
</msxsl:script>

</xsl:stylesheet>

Main XSLT: MyTransformer.xsl ... that refers functions.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
        version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
        xmlns:msxsl="urn:schemas-microsoft-com:xslt" 
        xmlns:myfuncs="urn:mynamespace:mytable:transactions">

<xsl:output method="xml"/>    
<xsl:include href="functions.xsl" />  
<!--<xsl:variable name="trade_cur_bal" select="myfuncs:getOpenBalance(100)"/>-->
<xsl:template match="/">
    <Response>
            <!-- Some working code here -->
     </Response>
</xsl:template>

</xsl:stylesheet>

JS Code

var domXsl  = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");

/*
 // In case of IE9 .... 
 var domXsl  = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
*/

var domHTML = new ActiveXObject("Msxml2.XSLTemplate.4.0");
/*
 // In case of IE9 .... 
var domHTML = new ActiveXObject("Msxml2.XSLTemplate.6.0");
*/

domXsl.async=false;
domXsl.load("MyTransformer.xsl");
domHTML.stylesheet = domXsl;

var domData = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.4.0");
var input = "<MyInputData></MyInputData>"
domData.loadXML(input);

var result = tranform(domHTML, domData); //Works for MSXML 4.0 and fails for MSXML 6.0

function transform(template_, input_) { 
    var output = "";
    if (input_ != null  && input_.xml != "") {
        var proc = template_.createProcessor();
        proc.input = input_;
        proc.transform();
        output = proc.output;
        delete proc;
    }   
    return output;
}

Can someone guide me where am I going wrong w.r.t. MSXML6 or IE9?

Thx.

Was it helpful?

Solution 2

I got this fixed by removing the versions (4 and 6) form the activeX class ID

e.g. new ActiveXObject("Msxml2.FreeThreadedDomDocument") etc.

OTHER TIPS

With MSXML 6 use of script inside XSLT is disabled by default for security reasons, so you need to explicitly enable it by calling

var domXsl  = new ActiveXObject("Msxml2.FreeThreadedDOMDocument.6.0");
domXsl.setProperty("AllowXsltScript", true);

And additionally to allow the use of xsl:import or xsl:include you also need to set

domXsl.setProperty("ResolveExternals", true);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top