XSLTProcessor.transformToDocument始终使用Chrome返回null

时间:2019-06-28 14:23:54

标签: javascript xml google-chrome xslt

我正在JavaScript中使用XSLTProcessor通过应用样式表来转换某些XML。该代码将一直工作到使用transformToDocument方法。此方法的返回值始终为null。

我希望resultDOM的输出为XMLDocument,但实际输出为null。

xslText是一个xsl:stylesheet。使用xslDom.loadXML(xslText)在IE中运行的JavaScript可以正常工作。如果我更改代码以使用下面的var xslText5可以工作,但是var xslText7不能。

var xslText5 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">   <xsl:template match=\"/\">                <html><body>  <h2>test00</h2>             </body></html>   </xsl:template></xsl:stylesheet>";


var xslText7 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">   <xsl:template match=\"/\">                <html><body>  <h2>test00</h2>      <xsl:for-each select=\"Template/top/Room/Day/Schedule[@Sakey=$inRoomSchedSakey]\">         <h2>test11</h2>      </xsl:for-each>    </body></html>   </xsl:template></xsl:stylesheet>";                                  

var parser=new DOMParser();
xslDom2=parser.parseFromString(xslText7,"text/xml");
this.xslProcessor2 =  new XSLTProcessor();
this.xslProcessor2.importStylesheet(xslDom2);
var resultDOM = this.xslProcessor2.transformToDocument(xml.xmlDom);

var serializer = new XMLSerializer();
var output = serializer.serializeToString(resultDOM);

//Here is the xml (variable 'xml' above)
<?xml version="1.0"?>
<Template><top><criteria end="5:00 PM" start="7:00 AM" location="Indianapolis"/><Room Sakey="1"><Name><![CDATA[Classroom #01]]><Capacity>24</Capacity><OpenReserve>NO</OpenReserve><Configuration>Classroom</Configuration><Role>ROOMMGR</Role><Location Sakey="24965"><Day Date="2019/07/01"><Schedule Sakey="159944"><StartTime>47</StartTime><EndTime>55</EndTime><Reason><![CDATA[]]></Reason><PersonReserving><![CDATA[ANTHONY MISNER]]></PersonReserving><StartTimeString>11:30 AM</StartTimeString><EndTimeString>1:30 PM</EndTimeString><CourseTitle/><ProcessedBy Sakey="S000027819"><Email><![CDATA[
anthony.j.misner.ctr@mail.mil]]></Email><Name><![CDATA[ANTHONY MISNER]]></Name></ProcessedBy><Cancelled>NO</Cancelled></Schedule></Day><Day Date="2019/07/02"/><Day Date="2019/07/03"><Day Date="2019/07/04"/><Day Date="2019/07/05"/></Room></top></Template>

0 个答案:

没有答案