【问题标题】:Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. in Chrome无法在“节点”上执行“附加孩子”:参数 1 不是“节点”类型。在铬
【发布时间】:2017-08-04 18:37:51
【问题描述】:

Chrome 给我

在“Node”上执行“appendChild”失败:参数 1 不是“Node”类型。

IE 11 给了我

行:31 错误:样式表不包含文档元素。样式表可能是空的,也可能不是格式良好的 XML 文档。

当我按 F12 时:

"'xsl:stylesheet' 上的属性 'encoding' 无效。\r\n"

实际代码是:

<!DOCTYPE html>
<!-- saved from url=(0016)http://localhost -->
<html>
<head>
<script>


function loadXMLDoc()
{
if (window.ActiveXObject)
  {
  xhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
else 
  {
  xhttp = new XMLHttpRequest();
  }
xhttp.open("GET", "http://localhost:23100/ENG_ProcessingTemplate.xsl", false);
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11
xhttp.send("");
return xhttp.responseXML;
}

function displayResult()
{
xml = loadXMLDoc("http://localhost:23100/ProcessingReport.xml");
xsl = loadXMLDoc("http://localhost:23100/ENG_ProcessingTemplate.xsl");
// code for IE
if (window.ActiveXObject || xhttp.responseType == "msxml-document")
  {
  ex = xml.transformNode(xsl);
  document.getElementById("example").innerHTML = ex;
  }
// code for Chrome, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
  {
  xsltProcessor = new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml, document);
  document.getElementById("example").appendChild(resultDocument);
  }
}
</script>
</head>
<body onload="displayResult()">
<div id="example" />
</body>
</html>

XML:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="./ReportViewer.aspx?XSL=1"?>
<report>
<titledata>
<date>5555/5555/5555</date>
<time>08:26:58</time>
</titledata>
<ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.4796.ZZXCV </FileName><ProcTime>5555/5555/5555 08:26:00</ProcTime><Message>6File loaded successfully  </Message><OriginID>4796 ZZXCV </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.994514555590_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:26:00</ProcTime><Message> File loaded successfully  </Message><OriginID>99451 .</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.3448119.555594_5555_5555_5555</FileName><ProcTime>5555/5555/5555 08:25:59</ProcTime><Message> File loaded successfully  </Message><OriginID>3448119 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.2395.4555541_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:58</ProcTime><Message> File loaded successfully  </Message><OriginID>2395 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.2395.55534_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:57</ProcTime><Message> File loaded successfully  </Message><OriginID>2395 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.15970.Payroll_ _4555587_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:56</ProcTime><Message> File loaded successfully  </Message><OriginID>15970 DDDDX I SERV</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.2395.GDD_455555555_5555_30_5555</ZZXVFileName><ProcTime>5555/5555/5555 08:25:56</ProcTime><Message> File loaded successfully  </Message><OriginID>2395 Flavorite Foods GDDS</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.55558507.GDD_4555593_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:54</ProcTime><Message> File loaded successfully  </Message><OriginID>55558507 ZZXV AND</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.55558569.GDD_4555598_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:54</ProcTime><Message> File loaded successfully  </Message><OriginID>55558569 DGSG IDEAS GDDS</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.133383.GDD_4555597_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:54</ProcTime><Message> File loaded successfully  </Message><OriginID>133383 GDSGS</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.55554.GDDS 01_PPD_4555584_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:53</ProcTime><Message> File loaded successfully  </Message><OriginID>55554 GDDS GDDS</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.117437.GDD_4555591_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:52</ProcTime><Message> File loaded successfully  </Message><OriginID>117437 DDDDX SI</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.118796.GDD_4555589_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:52</ProcTime><Message> File loaded successfully  </Message><OriginID>118796 Environmental Sciences </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.116188.Payroll-Weekly_PPD_4555583_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:51</ProcTime><Message> File loaded successfully  </Message><OriginID>116188 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.11.GDGDC_41190_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:50</ProcTime><Message> File loaded successfully  </Message><OriginID>11 A</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.10815555.GDD_4555581_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:49</ProcTime><Message> File loaded successfully  </Message><OriginID>10815555 ZZXV </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.10815555.GDD_4555580_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:48</ProcTime><Message> File loaded successfully  </Message><OriginID>10815555 ZZXV ZZXV</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.106002.6915 &amp; 7115_PPD_4555558_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:47</ProcTime><Message> File loaded successfully  </Message><OriginID>106002 L</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.106418. 555595_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:47</ProcTime><Message> File loaded successfully  </Message><OriginID>106418 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.104685.D_4555599_5555_5555_5555</FileName><ProcTime>5555/5555/5555 08:25:46</ProcTime><Message> File loaded successfully  </Message><OriginID>104685 ZZXV GDDS</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.10394.GDGDC GDD_4555579_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:45</ProcTime><Message> File loaded successfully  </Message><OriginID>10394 ZZXV LI</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.102372.GDD_4555573_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:44</ProcTime><Message> File loaded successfully  </Message><OriginID>102372 TOBAGO REGIONAL HEALTH </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.102398.GDD_41119_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:44</ProcTime><Message> File loaded successfully  </Message><OriginID>102398 P5555 CO</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.10237.GDD_4555562_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:41</ProcTime><Message> File loaded successfully  </Message><OriginID>10237 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.10237.GDD_41164_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:40</ProcTime><Message> File loaded successfully  </Message><OriginID>10237 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.10237.GDD_41160_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:39</ProcTime><Message> File loaded successfully  </Message><OriginID>10237 T</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.100097_4555592_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:38</ProcTime><Message> File loaded successfully  </Message><OriginID>100097 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.102353._4555527_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:38</ProcTime><Message> File loaded successfully  </Message><OriginID>102353 /OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.100035.GDD_4555578_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:37</ProcTime><Message> File loaded successfully  </Message><OriginID>100035 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.100029.GDD_4555586_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:34</ProcTime><Message> File loaded successfully  </Message><OriginID>100029 GDDS</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.100029.GDD_4555588_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:34</ProcTime><Message> File loaded successfully  </Message><OriginID>100029</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.100000.41307_5555_5555_5555</FileName><ProcTime>5555/5555/5555 08:25:33</ProcTime><Message> File loaded successfully  </Message><OriginID>100000 GDDS</OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.100029.GDD_4555585_5555_30_5555</FileName><ProcTime>5555/5555/5555 08:25:33</ProcTime><Message> File loaded successfully  </Message><OriginID>100029 </OriginID></ProcessingLog><ProcessingLog><IDProcess>E</IDProcess><FileName>0921.0921.100000._5555_5555_5555</FileName><ProcTime>5555/5555/5555 08:25:32</ProcTime><Message> File loaded successfully  </Message><OriginID>100000 DDDDX GDDS</OriginID></ProcessingLog><ProcessingLog><IDProcess>A</IDProcess><FileName>1010090.001.1</FileName><ProcTime>5555/5555/5555 05:17:23</ProcTime><Message>1082 The payments were generated successfully  </Message></ProcessingLog><ProcessingLog><IDProcess>D</IDProcess><FileName>_5555555530.txt</FileName><ProcTime>5555/5555/5555 05:17:13</ProcTime><Message> File loaded successfully  </Message></ProcessingLog><ProcessingLog><IDProcess>M</IDProcess><FileName></FileName><ProcTime>5555/5555/5555 01:00:26</ProcTime><Message>23 dat  </Message></ProcessingLog>
</report>

XSL:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" encoding="ISO-8859-1">
<HTML xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <META HTTP-EQUIV="Content-Type" CONTENT="application/xml; charset=ISO-8859-1"></META>
    <BODY>
        <xsl:for-each select="report/titledata">
            <table width="80%" border="0">
                <tr>
                    <td width="55%" align="center">
                        <font face="tahoma">
                            <b>
                                <font size="3">Processing Log</font>
                            </b>
                        </font>
                    </td>
                    <td width="20%" align="center">
                        <font face="tahoma" size="2">
                            <b>
                                <xsl:value-of select="date"/>
                            </b>
                        </font>
                    </td>
                    <td width="25%" align="center">
                        <font face="tahoma" size="2">
                            <b>
                                <xsl:value-of select="time"/>
                            </b>
                        </font>
                    </td>
                </tr>
            </table>
        </xsl:for-each>
        <br></br>
        <div width="100%">
            <table width="95%" align="center">
                <tr>
                    <td width="45%" float="left">
                        <table>
                            <tr>
                                <td bgcolor="black">
                                    <font face="tahoma" size="1" color="white">
                                        <b>PayBank Manual Process</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>O = ON-US Files Generation</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>N = Not ON-US Files Generation</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>I = Payment Files Collection</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>R = Authorizations and Returns Collection</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>V = Verification Answer File Collection</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>G = Propietary Files Generation</b>
                                    </font>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td width="45%" float="right">
                        <table>
                            <tr>
                                <td bgcolor="black">
                                    <font face="tahoma" size="1" color="white">
                                        <b>PayBank Scheduler Process</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>P = ON-US Files Generation</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>A = Not ON-US Files Generation</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>E = Payment Files Collection</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>D = Authorizations and Returns Collection</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>L = Verification Answer File Collection</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>C = Propietary Files Generation</b>
                                        </font>
                                    </td>
                                </tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>T = Automatic Return Report Generation</b>
                                    </font>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        <br></br>
        <table width="100%" border="0">
            <tr bgcolor="BLACK">
                <td width="5%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Proc</b>
                    </font>
                </td>
                <td width="15%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Date</b>
                    </font>
                </td>
                <td width="15%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>File</b>
                    </font>
                </td>
                <td width="35%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Error</b>
                    </font>
                </td>
                <td width="15%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Origin</b>
                    </font>
                </td>
                <td width="8%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Record</b>
                    </font>
                </td>
                <td width="7%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Batch</b>
                    </font>
                </td>
            </tr>
            <xsl:for-each select="report/ProcessingLog">
                <tr>
                    <td width="5%" align="center">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="IDProcess"/>
                        </font>
                    </td>
                    <td width="15%" align="center">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="ProcTime"/>
                        </font>
                    </td>
                    <td width="15%" align="left">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="FileName"/>
                        </font>
                    </td>
                    <td width="35%" align="left">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="Message"/>
                        </font>
                    </td>
                    <td width="15%" align="left">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="OriginID"/>
                        </font>
                    </td>
                    <td width="8%" align="right">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="Record"/>
                        </font>
                    </td>
                    <td width="7%" align="right">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="Batch"/>
                        </font>
                    </td>
                </tr>
            </xsl:for-each>
        </table>
    </BODY>
</HTML>
</xsl:stylesheet>

谁能帮我解决这个问题。

【问题讨论】:

  • 使用 F12 打开浏览器的开发者工具并检查控制台是否有任何错误,尤其是加载文档是否有效。在任何情况下,您似乎都想给您的函数loadXMLDoc 一个参数(例如function loadXMLDoc(url) {),然后在公开调用中使用它,例如xhttp.open('GET', url, false).
  • XSL 文件:pastebin.com/tfPN8M3i XML 文件:pastebin.com/XgDZmrcG

标签: javascript xml xslt


【解决方案1】:

一个最小的 XSLT 1.0 样式表应该是

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<html>
    <head>
       <title>Report</title>
    </head>        
    <body>
        <xsl:for-each select="report/titledata">
            <table width="80%" border="0">
                <tr>
                    <td width="55%" align="center">
                        <font face="tahoma">
                            <b>
                                <font size="3">Processing Log</font>
                            </b>
                        </font>
                    </td>
                    <td width="20%" align="center">
                        <font face="tahoma" size="2">
                            <b>
                                <xsl:value-of select="date"/>
                            </b>
                        </font>
                    </td>
                    <td width="25%" align="center">
                        <font face="tahoma" size="2">
                            <b>
                                <xsl:value-of select="time"/>
                            </b>
                        </font>
                    </td>
                </tr>
            </table>
        </xsl:for-each>
        <br></br>
        <div width="100%">
            <table width="95%" align="center">
                <tr>
                    <td width="45%" float="left">
                        <table>
                            <tr>
                                <td bgcolor="black">
                                    <font face="tahoma" size="1" color="white">
                                        <b>PayBank Manual Process</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>O = ON-US Files Generation</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>N = Not ON-US Files Generation</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>I = Payment Files Collection</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>R = Authorizations and Returns Collection</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>V = Verification Answer File Collection</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>G = Propietary Files Generation</b>
                                    </font>
                                </td>
                            </tr>
                        </table>
                    </td>
                    <td width="45%" float="right">
                        <table>
                            <tr>
                                <td bgcolor="black">
                                    <font face="tahoma" size="1" color="white">
                                        <b>PayBank Scheduler Process</b>
                                    </font>
                                </td>
                            </tr>
                            <tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>P = ON-US Files Generation</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>A = Not ON-US Files Generation</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>E = Payment Files Collection</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>D = Authorizations and Returns Collection</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>L = Verification Answer File Collection</b>
                                        </font>
                                    </td>
                                </tr>
                                <tr>
                                    <td >
                                        <font face="tahoma" size="1" >
                                            <b>C = Propietary Files Generation</b>
                                        </font>
                                    </td>
                                </tr>
                                <td >
                                    <font face="tahoma" size="1" >
                                        <b>T = Automatic Return Report Generation</b>
                                    </font>
                                </td>
                            </tr>
                        </table>
                    </td>
                </tr>
            </table>
        </div>
        <br></br>
        <table width="100%" border="0">
            <tr bgcolor="BLACK">
                <td width="5%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Proc</b>
                    </font>
                </td>
                <td width="15%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Date</b>
                    </font>
                </td>
                <td width="15%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>File</b>
                    </font>
                </td>
                <td width="35%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Error</b>
                    </font>
                </td>
                <td width="15%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Origin</b>
                    </font>
                </td>
                <td width="8%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Record</b>
                    </font>
                </td>
                <td width="7%" align="center">
                    <font face="tahoma" size="1" color="WHITE">
                        <b>Batch</b>
                    </font>
                </td>
            </tr>
            <xsl:for-each select="report/ProcessingLog">
                <tr>
                    <td width="5%" align="center">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="IDProcess"/>
                        </font>
                    </td>
                    <td width="15%" align="center">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="ProcTime"/>
                        </font>
                    </td>
                    <td width="15%" align="left">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="FileName"/>
                        </font>
                    </td>
                    <td width="35%" align="left">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="Message"/>
                        </font>
                    </td>
                    <td width="15%" align="left">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="OriginID"/>
                        </font>
                    </td>
                    <td width="8%" align="right">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="Record"/>
                        </font>
                    </td>
                    <td width="7%" align="right">
                        <font face="tahoma" size="1">
                            <xsl:value-of select="Batch"/>
                        </font>
                    </td>
                </tr>
            </xsl:for-each>
        </table>
    </body>
</html>
</xsl:template>
</xsl:stylesheet>

如果您想使用 transformToFragment,那么最好只返回一个在语义上适合您 appendChild 的元素的 HTML 片段,而不是完整的文档。但是,我认为浏览器会复制上述内容。

确保您还修复了加载 XML 和 XSLT 的方法以获取参数,即更改

function loadXMLDoc()
{
if (window.ActiveXObject)
  {
  xhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
else 
  {
  xhttp = new XMLHttpRequest();
  }
xhttp.open("GET", "http://localhost:23100/ENG_ProcessingTemplate.xsl", false);
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11
xhttp.send("");
return xhttp.responseXML;
}

function loadXMLDoc(url)
{
if (window.ActiveXObject)
  {
  xhttp = new ActiveXObject("Msxml2.XMLHTTP");
  }
else 
  {
  xhttp = new XMLHttpRequest();
  }
xhttp.open("GET", url, false);
try {xhttp.responseType = "msxml-document"} catch(err) {} // Helping IE11
xhttp.send("");
return xhttp.responseXML;
}

【讨论】:

  • 我使用了您在此处放置的 XSL 文件,并且没有收到任何错误,我在屏幕顶部获得了一个模板,但我没有从 xml 中获得任何数据。我不知道你的评论是什么意思。你能帮我把它弄糊涂吗(我不太了解 XML)
  • 查看编辑,问题不在于 XSLT 或 XML,而在于编写一个 Javascript 函数,该函数采用您在其主体中使用的参数。
  • 好的会试试。使用 IE 我没有收到错误,但使用 Chrome 我收到警告 >“提供的值 'msxml-document' 不是 XMLHttpRequestResponseType 类型的有效枚举值。”
【解决方案2】:

您能给我们提供您的 XML/XSL 示例吗?

这似乎是 client side XSLT processing,它依赖于浏览器来解析 XML。您始终可以检查和调试您的 XSL/XML 语法……如果它抛出错误,可能是因为它没有正确解析它,或者浏览器本身不支持您用来转换 XML 的任何版本的 XSL(不太可能)。

试试:

将 XSL/XML 文档放入您的项目中并将它们称为

xml = loadXMLDoc("ProcessingReport.xml");
xsl = loadXMLDoc("ENG_ProcessingTemplate.xsl");

没有 XML 和 XSL,很难确定问题的真正原因...

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2015-01-20
  • 2023-04-01
  • 2018-01-26
  • 2021-02-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-18
相关资源
最近更新 更多