简体   繁体   English

Xsl transformToDocument 不适用于 Chrome 浏览器,但适用于 Firefox

[英]Xsl transformToDocument is not working in chrome browser but working in firefox

I am getting the xsl by calling aN URL and to parse that xml i am using below code snippent.我通过调用一个N URL 来获取xsl 并解析我使用下面代码片段的那个xml。

var xslt = getXSLTemplate(xslUri, params, xmlDoc);
    if (!xslt) {
        xslt = createXSLTemplateGeneric(xslUri, params, xmlDoc);
        if (xslt) {
            putXSLTemplate(xslUri, xslt);
        }
    }
    if (xslt) {
        xslt.clearParameters();
        var paramName = params[0];
        var paramValue = params[1];
        var result = "";
        for (var paramIdx = 0; paramIdx < paramName.length; paramIdx++) {
            xslt
                    .setParameter("", paramName[paramIdx],
                            paramValue[paramIdx]);
        }
        var transformDoc = xslt.transformToDocument(xmlDoc);
        var xmlSerializer = new XMLSerializer();

        if (transformDoc.firstChild != null) {
            var nodes = transformDoc.lastChild.childNodes;
            for (var i = 0; nodes[i]; ++i) {
                result += xmlSerializer.serializeToString(nodes[i]);
            }
            result = transformDoc.lastChild.xml;
        }
        return result;
    }

But this code is working in firefox where the same not working in chrome.但是此代码在 Firefox 中有效,而在 chrome 中同样无效。 Please let me know what is the mistake i am doing to parse the document or please let me know if description above is not enough for analysis.请让我知道我在解析文档时犯了什么错误,或者如果上面的描述不足以进行分析,请告诉我。

The result i am getting in chrome is as below我在 chrome 中得到的结果如下

<div xmlns="http://www.w3.org/1999/xhtml" id="alertMessages" style="width:400px;"></div>

where in firefox i am getting the right result.在 Firefox 中,我得到了正确的结果。

<table xmlns=\"http://www.w3.org/1999/xhtml\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\" class=\"panelContentTbl\" style=\"margin-left:14px; margin-top:14px;\"><tbody><tr><td valign=\"top\"><script id=\"doLogin\" cancelifviewbusy=\"\">try{ if(getFormInputByName(\"loginButton\").disabled == false){ var name = trimAll(getFormInputByName(\"username\").value); var pwd = trimAll(getFormInputByName(\"password\").value); if(name.length &gt; 0 &amp;&amp; pwd.length &gt; 0){   disableButton(\"loginButton\"); displayClientStatus(\"Authenticating user...\");  var nameArray = new Array(); var typeArray = new Array(); var valueArray = new Array();   nameArray.push(\"username\"); typeArray.push(TYPE_ATTRIBUTE); valueArray.push(name);   nameArray.push(\"password\"); typeArray.push(TYPE_ATTRIBUTE); valueArray.push(pwd);   loadAsyncPanelAction(\"loginWidget\", getActionUri('client', 'login'), nameArray, typeArray, valueArray, \"checkSecurityAuth(asyncPanelRequest);\");  } else{ panelAlert(\"Please enter your user ID and password.\",\"layouts/layout2010.1/xsl/widget/panel/login.xsl\");} } } catch(anErr){ errorAlert(\"doLogin\", SEVERITY_HIGH, anErr); } </script><script id=\"getPasswordHelp\" cancelifviewbusy=\"\">try{ var name = trimAll(getFormInputByName(\"username\").value); var nameArray = new Array(); var typeArray = new Array(); var valueArray = new Array(); nameArray.push(\"username\"); typeArray.push(TYPE_ATTRIBUTE); valueArray.push(name); displayClientStatus(\"Loading password assistant...\");loadAsyncPanelAction(\"loginWidget\", getActionUri('layout.widget', 'get-password-help'), nameArray, typeArray, valueArray, \"displayClientStatus('');\"); } catch(anErr){ errorAlert(\"getPasswordHelp\", SEVERITY_HIGH, anErr); } </script><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody><tr><td><div id=\"panelHeader\"><table width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody><tr class=\"panelHeader\"><td nowrap=\"yes\">User Login</td></tr></tbody></table></div></td></tr><tr><td valign=\"top\" style=\"padding:10px;\"><div id=\"panel\" style=\"330px\"><div style=\"white-space:normal;\"><instructions><span>Please enter your user ID and password.</span></instructions></div><div class=\"inputHeader\"></div><eventhandler id=\"initContent\" handler=\"var fi = getFormInputByName('username'); if (null != fi) fi.focus();\"> </eventhandler><table cellspacing=\"1\" cellpadding=\"0\" border=\"0\" class=\"panelForm\" id=\"loginForm\"><tbody><tr><td id=\"panelLabel\" style=\"width:120px;\">User ID *</td><td nowrap=\"true\" id=\"panelValue\" style=\"width:120;\"><input type=\"text\" id=\"inputProperty\" class=\"inputText\" name=\"username\" size=\"30\" required=\"FALSE\" onselectstart=\"setSelectable(this,true,event);\" ondragenter=\"event.returnValue = false;\" value=\"\" style=\"-moz-user-select:text;width:175pxpx;\" onkeypress=\"clickButtonOnEnter(event, 'loginButton');\" /></td></tr><tr><td id=\"panelLabel\" style=\"width:120px;\">Password *</td><td nowrap=\"true\" id=\"panelValue\" style=\"width:120;\"><input type=\"password\" class=\"inputText\" name=\"password-display\" size=\"30\" value=\"\" onselectstart=\"setSelectable(this,true,event);\" ondragenter=\"event.returnValue = false;\" style=\"-moz-user-select:text;width:175pxpx;\" onchange=\"getFormInputByName('password').value = this.value;\" onkeypress=\"clickButtonOnEnter(event, 'loginButton');\" /><input type=\"hidden\" id=\"inputProperty\" name=\"password\" value=\"\" /><eventhandler id=\"resizeContent\" handler=\"var pwd1 = getFormInputByName('password-display'); var pwd2 = getFormInputByName('password'); if (null != pwd1 &amp;&amp; null != pwd2) pwd1.value = pwd2.value;\"> </eventhandler></td></tr><tr><td id=\"panelLabel\"> </td><td id=\"panelValue\"><table cellspacing=\"0\" cellpadding=\"0\" border=\"0\"><tbody><tr><td nowrap=\"nowrap\" style=\"padding-right:6px;\"><input type=\"submit\" id=\"button\" name=\"loginButton\" value=\"Login\" title=\"\" style=\"width:70px;\" class=\"panelButton\" onclick=\"\n                            if(jQuery(this).hasClass('buttonDisabled') ||\n                            jQuery(this).hasClass('jQueryDisabled')) return;\n                            fireScript('doLogin'); \" /></td></tr></tbody></table></td></tr></tbody></table><div align=\"right\"><table><tbody><tr><td align=\"right\"><a class=\"blue\" style=\"padding-top:8px; cursor:pointer; white-space:nowrap;\" onclick=\"fireScript('getPasswordHelp');\">Forgot your password?</a></td></tr></tbody></table></div></div></td></tr><tr><td valign=\"top\" height=\"100%\" style=\"text-align:center;\" id=\"clientStatus\"></td></tr></tbody></table></td></tr></tbody></table>

There is no crash or error in any of the browser.任何浏览器都没有崩溃或错误。

It might depend on how you actually get the document xmlDoc in your case.这可能取决于您实际获取文档xmlDoc的方式。 If the document is retrieved using ajax DOES return the xhttp.responseXML and does NOT return xhttp.responseXML.documentElement .如果文档是使用AJAX检索不会返回的xhttp.responseXML返回xhttp.responseXML.documentElement

Both can be converted using XMLSerializer to a meaningful representation of the document but only the first statement is a viable parameter for the XSL Transformation.两者都可以使用 XMLSerializer 转换为有意义的文档表示,但只有第一条语句是 XSL 转换的可行参数。

If the latter is used the return value of the XSLTransformation (using either toDocument or toFragment function) is null in my case (using Chrome)如果使用后者,则 XSLTransformation 的返回值(使用 toDocument 或 toFragment 函数)在我的情况下为 null(使用 Chrome)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM