2010-05-30 88 views
1

所以,我使用XSLT的jQuery插件,这里是我的代码:组件返回故障代码:0x80600011 [nsIXSLTProcessorObsolete.transformDocument]

function AddPlotcardEventHandlers(){ 
    // some code 
} 

function reportError(exception){ 
    alert(exception.constructor.name + " Exception: " + ((exception.name) ? exception.name : "[unknown name]") + " - " + exception.message); 
} 

function GetPlotcards(){ 
    $("#content").xslt("../xml/plotcards.xml","../xslt/plotcards.xsl", AddPlotcardEventHandlers,reportError); 
} 

下面是修改后的jQuery插件。我说它的修改是因为我添加了成功和错误处理的回调函数。

/* 
* jquery.xslt.js 
* 
* Copyright (c) 2005-2008 Johann Burkard (<mailto:[email protected]>) 
* <http://eaio.com> 
* 
* Permission is hereby granted, free of charge, to any person obtaining a 
* copy of this software and associated documentation files (the "Software"), 
* to deal in the Software without restriction, including without limitation 
* the rights to use, copy, modify, merge, publish, distribute, sublicense, 
* and/or sell copies of the Software, and to permit persons to whom the 
* Software is furnished to do so, subject to the following conditions: 
* 
* The above copyright notice and this permission notice shall be included 
* in all copies or substantial portions of the Software. 
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 
* USE OR OTHER DEALINGS IN THE SOFTWARE. 
* 
*/ 

/** 
* jQuery client-side XSLT plugins. 
* 
* @author <a href="mailto:[email protected]">Johann Burkard</a> 
* @version $Id: jquery.xslt.js,v 1.10 2008/08/29 21:34:24 Johann Exp $ 
*/ 
(function($) { 
    $.fn.xslt = function() { 
     return this; 
    } 
    var str = /^\s*</; 
    if (document.recalc) { // IE 5+ 
     $.fn.xslt = function(xml, xslt, onSuccess, onError) { 

      try{ 

       var target = $(this); 

       var change = function() { 
        try{ 
         var c = 'complete'; 
         if (xm.readyState == c && xs.readyState == c) { 
           window.setTimeout(function() { 
            target.html(xm.transformNode(xs.XMLDocument)); 
            if (onSuccess) onSuccess(); 
           }, 50); 
         } 
        }catch(exception){ 
         if (onError) onError(exception); 
        } 
       }; 

       var xm = document.createElement('xml'); 
       xm.onreadystatechange = change; 
       xm[str.test(xml) ? "innerHTML" : "src"] = xml; 

       var xs = document.createElement('xml'); 
       xs.onreadystatechange = change; 
       xs[str.test(xslt) ? "innerHTML" : "src"] = xslt; 

       $('body').append(xm).append(xs); 
       return this; 

      }catch(exception){ 
       if (onError) onError(exception); 
      } 
     }; 
    } 
    else if (window.DOMParser != undefined && window.XMLHttpRequest != undefined && window.XSLTProcessor != undefined) { // Mozilla 0.9.4+, Opera 9+ 
     var processor = new XSLTProcessor(); 
     var support = false; 
     if ($.isFunction(processor.transformDocument)) { 
      support = window.XMLSerializer != undefined; 
     } 
     else { 
      support = true; 
     } 
     if (support) { 
      $.fn.xslt = function(xml, xslt, onSuccess, onError) { 

       try{ 

        var target = $(this); 
        var transformed = false; 

        var xm = { 
         readyState: 4 
        }; 
        var xs = { 
         readyState: 4 
        }; 

        var change = function() { 
         try{ 
          if (xm.readyState == 4 && xs.readyState == 4 && !transformed) { 
           var processor = new XSLTProcessor(); 
           if ($.isFunction(processor.transformDocument)) { 
            // obsolete Mozilla interface 
            resultDoc = document.implementation.createDocument("", "", null); 
            processor.transformDocument(xm.responseXML, xs.responseXML, resultDoc, null); 
            target.html(new XMLSerializer().serializeToString(resultDoc)); 
           } 
           else { 
            processor.importStylesheet(xs.responseXML); 
            resultDoc = processor.transformToFragment(xm.responseXML, document); 
            target.empty().append(resultDoc); 
           } 
           transformed = true; 
           if (onSuccess) onSuccess(); 
          } 
         }catch(exception){ 
          if (onError) onError(exception); 
         } 
        }; 

        if (str.test(xml)) { 
         xm.responseXML = new DOMParser().parseFromString(xml, "text/xml"); 
        } 
        else { 
         xm = $.ajax({ dataType: "xml", url: xml}); 
         xm.onreadystatechange = change; 
        } 

        if (str.test(xslt)) { 
         xs.responseXML = new DOMParser().parseFromString(xslt, "text/xml"); 
         change(); 
        } 
        else { 
         xs = $.ajax({ dataType: "xml", url: xslt}); 
         xs.onreadystatechange = change; 
        } 

       }catch(exception){ 
        if (onError) onError(exception); 
       }finally{ 
        return this; 
       } 
      }; 
     } 
    } 
})(jQuery); 

而且,这里是我的错误信息:

对象异常:未知的名称 - 组件返回故障代码:0x80600011 [nsIXSLTProcessorObsolete.transformDocument]

下面是对的信息我用来测试的浏览器(安装了Firebug v1.5.4加载项):

Mozilla/5.0(Windows; U; Windows NT 6.1; EN-US; RV:1.9.2.3)的Gecko/20100401火狐/ 3.6.3

这里是我的XML:

<?xml version="1.0" encoding="ISO-8859-1"?> 
<plotcardCollection sortby="order"> 
    <plotcard order="2" id="1378"> 
     <name><![CDATA[[placeholder for name of plotcard 1378]]]></name> 
     <content><![CDATA[[placeholder for content of plotcard 1378]]]></content> 
     <tagCollection> 
      <tag id="3"><![CDATA[[placeholder for tag with id=3]]]></tag> 
      <tag id="7"><![CDATA[[placeholder for tag with id=7]]]></tag> 
     </tagCollection> 
    </plotcard> 
    <plotcard order="1" id="2156"> 
     <name><![CDATA[[placeholder for name of plotcard 2156]]]></name> 
     <content><![CDATA[[placeholder for content of plotcard 2156]]]></content> 
     <tagCollection> 
      <tag id="2"><![CDATA[[placeholder for tag with id=2]]]></tag> 
      <tag id="9"><![CDATA[[placeholder for tag with id=9]]]></tag> 
     </tagCollection> 
    </plotcard> 
</plotcardCollection> 

这里是我的XSLT:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/plotcardCollection"> 
    <xsl:variable name="sortby" select="@sortby" /> 
    <xsl:for-each select="plotcard"> 
     <xsl:sort select="$sortby" data-type="number" order="ascending"/> 
     <div> 

      <!-- Start Plotcard --> 
      <xsl:attribute name="class">Plotcard</xsl:attribute> 
      <xsl:for-each select="@"> 
       <xsl:value-of select="name()"/> 
       <xsl:text>='</xsl:text> 
       <xsl:if test="name() = 'id'"> 
        <xsl:text>Plotcard-</xsl:text> 
       </xsl:if> 
       <xsl:value-of select="." /> 
       <xsl:text>'</xsl:text> 
      </xsl:for-each> 

      <!-- Start Plotcard Name Section --> 
      <div> 
       <xsl:attribute name="class"> 
        <xsl:text disable-output-escaping="yes">PlotcardName</xsl:text> 
       </xsl:attribute> 
       <xsl:value-of select="name/text()"/> 
      </div> 

      <!-- Start Plotcard Content Section --> 
      <div> 
       <xsl:attribute name="class"> 
        <xsl:text disable-output-escaping="yes">PlotcardContent</xsl:text> 
       </xsl:attribute> 
       <xsl:value-of select="content/text()"/> 
      </div> 
     </div> 
    </xsl:for-each> 
    </xsl:template> 
</xsl:stylesheet> 

我真的不知道该怎么做这个....任何想法?

+0

可以显示XSLT文件或更好的现场演示,所以我们可以看到 – redsquare 2010-05-30 06:46:24

+0

是的,我只是说它在我看到您的评论之前。 – bitcycle 2010-05-30 06:47:52

回答

1

所以,我想出了这一个。显然,我指的是属性名称变量不正确。

  <xsl:for-each select="@"> 
       <xsl:value-of select="name()"/> 
       <xsl:text>='</xsl:text> 
       <xsl:if test="name() = 'id'"> 
        <xsl:text>Plotcard-</xsl:text> 
       </xsl:if> 
       <xsl:value-of select="." /> 
       <xsl:text>'</xsl:text> 
      </xsl:for-each> 

而且应该是这样的:XSLT那是失败就是这样做的部分

 <xsl:for-each select="@*"> 
      <xsl:variable name="attrName"> 
       <xsl:value-of select="name()"/> 
      </xsl:variable> 
      <xsl:attribute name="{$attrName}"> 
      <xsl:if test="name() = 'id'"> 
       <xsl:text>Plotcard-</xsl:text> 
      </xsl:if> 
      <xsl:value-of select="."/> 
      </xsl:attribute> 
     </xsl:for-each> 
0

首先你能尝试添加一个版本号XSLT文件

e.g

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0"> 

此外,我注意到你用UTF8的XSLT和ISO-8859-1的XML。很长一段时间,因为我用任何细节xml/xslt,但这可能会导致问题?

+0

我已经更新了XML以使用UTF-8,并且我添加了版本号,但似乎都没有解决该问题。 – bitcycle 2010-05-30 06:52:16

+0

耻辱,对不起,没有这个地方,能够改变事情,我不能看到这个问题。希望别人可以! – redsquare 2010-05-30 06:57:16

+0

这是我为我的妻子创建的网站的代码。我还没有公开发布。 – bitcycle 2010-05-30 06:58:56