我有一种将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