我有一種將XSLT樣式Chrome和Safari XSLT使用JavaScript
Test.Xml.xslTransform = function(xml, xsl) {
try {
// code for IE
if (window.ActiveXObject) {
ex = xml.transformNode(xsl);
return ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument) {
xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml, document);
return resultDocument;
}
} catch (exception) {
if (typeof (exception) == "object") {
if (exception.message) {
alert(exception.message);
}
} else {
alert(exception);
}
}
下面的代碼的代碼工作在IE和Firefox,但無法在Chrome和Safari。任何想法爲什麼?
更新
ResultDocument = xsltProcessor.transformToFragment(xml, document);
線的上方返回null。沒有錯誤被拋出。
更新
的代碼不工作作爲XSLT文件中包含的xsl:包括。需要找到一種方式來獲得包括工作,我會在這裏貼進步
更新
已recomended我使用http://plugins.jquery.com/project/Transform/插件。我試圖使用客戶端庫文件作爲包含在這裏工作的示例(http://daersystems.com/jquery/transform/)。
該代碼在IE中工作,但仍不在Chrome中。
Test.Xml.xslTransform = function(xml, xsl) {
try {
$("body").append("<div id='test' style='display:none;'></div>");
var a = $("#test").transform({ xmlobj: xml, xslobj: xsl });
return a.html();
}
catch (exception) {
if (typeof (exception) == "object") {
if (exception.message) {
alert(exception.message);
}
} else {
alert(exception);
}
}
}
XML和XSL是傳遞兩個對象。
更新
我試圖改變XSL文件是很簡單的東西,沒有包括和Chrome依然沒有應用樣式表和IE是。正被帶來了作爲一個對象的XSL是:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:rs="urn:schemas-microsoft-com:rowset"
xmlns:z="#RowsetSchema"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:spsoap="http://schemas.microsoft.com/sharepoint/soap/"
>
<xsl:output method="html"/>
<xsl:template match="/">
<h1>test</h1>
</xsl:template>
</xsl:stylesheet>
更新
,我想是被應用到XML文件的XSL最終結果。其中包含xsl文件。我希望trasnfer理想地在客戶端上發生。
更新 魯珀特,你可以更新與XML,以及如何你調用Test.Xml.xslTransform的問題?
我使用IE8
<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><SearchListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"><SearchListItemsResult><listitems xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema">
<rs:data ItemCount="1">
<z:row ows_Title="Test" ows_FirstName="Test 4" ows_UniqueId="74;#{1A16CF3E-524D-4DEF-BE36-68A964CC24DF}" ows_FSObjType="74;#0" ows_MetaInfo="74;#" ows_ID="74" ows_owshiddenversion="10" ows_Created="2009-12-29 12:21:01" ows_FileRef="74;#Lists/My List Name/74_.000" ReadOnly="False" VerificationRequired="0"/>
</rs:data>
</listitems></SearchListItemsResult></SearchListItemsResponse></soap:Body></soap:Envelope>
的代碼被稱爲如下的XML:
xsl = Test.Xml.loadXMLDoc("/_layouts/xsl/xsl.xslt");
var doc = Test.Xml.xslTransform(xData.responseXML, xsl);
擴展數據是由Web服務返回的XML。
請提供更多信息,例如異常消息。我建議使用Sarissa(用於跨瀏覽器XML/XSLT的開源JavaScript)。 – 2010-01-11 13:56:26
也許XML上的XSLT沒有返回任何結果,因爲XSLT中的模板都沒有匹配XML文檔。查看我的博客「避免常見的XSLT錯誤」(http://dev.ektron.com/blogs.aspx?id=22956),特別是鏈接「XSLT:namespaces」(http://dev.ektron.com/kb_article.aspx ?id = 481) – 2010-01-11 15:25:17
在xslt中使用xsl:include看起來有問題。目前正在尋找方法。 – Rupert 2010-01-11 17:34:57