Chrome给了我
无法在'Node'上执行'appendChild':参数1不是'Node'类型。
IE 11给了我
线:31 错误:样式表不包含文档元素。样式表可能为空,也可能不是格式良好的XML文档。
当我按F12时:
“属性'编码'在'xsl:stylesheet'上无效。\ 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 & 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>
有人可以帮我解决这个问题。
答案 0 :(得分:0)
您能举例说明您的XML / XSL吗?
这似乎是client side XSLT processing,它依赖于浏览器来解析XML。您可以随时检查和调试您的XSL / XML语法...如果它发出错误,可能是因为它没有正确解析它,或者浏览器本身不支持无论你使用什么版本的XSL来转换XML(不太可能)。
尝试:
将XSL / XML文档放在项目中并将其称为
xml = loadXMLDoc("ProcessingReport.xml");
xsl = loadXMLDoc("ENG_ProcessingTemplate.xsl");
如果没有XML和XSL,很难确定实际导致问题的原因......
答案 1 :(得分:0)
最小的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;
}