我在使用下面的xsl轉換xml文檔時遇到了一些麻煩。該代碼使用xmlDoc.transformNode在IE上工作,但以下代碼在chrome中不起作用 - resultDocument返回null。在IE瀏覽器中工作的XSL轉換,而不是在Chrome中
var xslString = "<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="options">
<div id="divAllOpt" class="sDiv" ALL="1" style="FONT-WEIGHT:bold;">
All
</div>
<div id="divGroupOnOpt" class="sDiv" GROUP="1" style="FONT-WEIGHT:bold;">
Group By
</div>
<xsl:apply-templates select="option[. != '']">
<xsl:sort select="."/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="option">
<div class="sDiv">
<xsl:choose>
<xsl:when test="@value">
<xsl:attribute name="VALUE">
<xsl:value-of select="@value"></xsl:value-of>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="VALUE">
<xsl:value-of select="."></xsl:value-of>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
<xsl:attribute name="title">
<xsl:value-of select="."></xsl:value-of>
</xsl:attribute>
<xsl:value-of select="."></xsl:value-of>
<xsl:if test="@count">
(<xsl:value-of select="@count"></xsl:value-of>)
</xsl:if>
</div>
</xsl:template>
</xsl:stylesheet>";
var xsltProcessor = new XSLTProcessor();
var xslSheet = new DOMParser().parseFromString(xslString, 'application/xml');
xsltProcessor.importStylesheet(xslSheet);
var resultDocument = xsltProcessor.transformToFragment(xmlDoc.documentElement, document);
,我試圖轉換XML文檔(xmlDoc.documentElement.outerHTML)如下圖所示 -
"<options>
<option count="3">ABC</option>
<option count="8">XYZ</option>
<option count="32">CVB</option>
<option count="1">TST</option>
<option count="2">CNN</option>
</options>"
任何想法?謝謝。
編輯 - 我把jsfiddle放在一起 - 在Firefox中工作,但不在Chrome中。
http://jsfiddle.net/facm1ptz/5/
我同意。我試圖修改一個使用xml島(!!!)的舊應用程序,並試圖在最終重寫之前使用chrome中的基本功能來獲取一些頁面。感謝您的迴應! – Bookamp 2014-09-24 17:57:09