javascript - XSLT transformation using browser -


i need transform xml data html using xslt transformation. have predefined xslt files work in ie10, not in chrome or firefox. firefox doesn't work @ all. chrome there xslt files work fine same xml data, , there others doesn't work. need know whether there limitations/specification xslt files cross browser xslt files. example have 2 xslt files 1. whole content in <xsl:template match='/'> tag (works chrome) 2. whole content in different tags, of them <xsl:variable> tags, others <xsl:template> (doesn't work chrome)

here do

    //load xsl , xml files paths , make transformation             loadxmlfile(xslpath, function (loadedxsl) {                  loadxmlfile(xmlpath, function (loadedxml) {                     var output = transformxml(loadedxml, loadedxsl, null);                  }, function (errmsg) {                     alert(errmsg);                 });             }, function (errmsg) {                 alert(errmsg);             });  //function loading local files function loadxmlfile(path, donefunction, errorfunction) {     //for ie     if (window.activexobject) {         $.ajax(path, {             cache: true,             crossdomain: true,             datatype: 'text',         }).done(function (data) {             donefunction(parsetexttoxml(data));         }).error(function (data) {             alert(data.statustext + "-" + data.responsetext);         });     }     //for firefox/chrome     else {         $.ajax(path, {             type: 'get',             contenttype: 'text/xml',             datatype: 'xml',             mimetype: 'text/xml',         }).done(function (data) {             donefunction(data);         }).error(function (xhr) {             errorfunction(xhr);         });     } }   //function transformation function transformxml(xmldoc, xsldoc, responsetype) {     var data;     if (window.activexobject || responsetype == "msxml-document") {         data = xmldoc.transformnode(xsldoc);     }         // code chrome, firefox, opera, etc.     else if (document.implementation && document.implementation.createdocument) {         var xsltprocessor = new xsltprocessor();         xsltprocessor.importstylesheet(xsldoc);          if (navigator.useragent.tolowercase().indexof('firefox') > -1) {             //do firefox-related activities             data = xsltprocessor.transformtodocument(xmldoc);         }         else {             data = xsltprocessor.transformtofragment(xmldoc, document);         }     }     return data; }    //xsl file content <?xml version="1.0" encoding="utf-8" standalone="yes" ?> <!--  |  | xslt rec compliant version of ie5 default stylesheet  |  | original version jonathan marsh  | http://msdn.microsoft.com/xml/samples/defaultss/defaultss.xsl  |  | conversion xslt 1.0 rec syntax steve muench  |  --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns="http://www.w3.org/1999/xhtml">   <xsl:output indent="no" method="html"/>    <xsl:template match="/">     <html>       <head>         <script>           <xsl:comment>             <![cdata[                   function f(e){                      if (e.classname=="ci") {                        if (e.children(0).innertext.indexof("\n")>0) fix(e,"cb");                      }                      if (e.classname=="di") {                        if (e.children(0).innertext.indexof("\n")>0) fix(e,"db");                      } e.id="";                   }                   function fix(e,cl){                     e.classname=cl;                     e.style.display="block";                     j=e.parentelement.children(0);                     j.classname="c";                     k=j.children(0);                     k.style.visibility="visible";                     k.href="#";                   }                   function ch(e) {                     mark=e.children(0).children(0);                     if (mark.innertext=="+") {                       mark.innertext="-";                       (var i=1;i<e.children.length;i++) {                         e.children(i).style.display="block";                       }                     }                     else if (mark.innertext=="-") {                       mark.innertext="+";                       (var i=1;i<e.children.length;i++) {                         e.children(i).style.display="none";                       }                     }                   }                   function ch2(e) {                     mark=e.children(0).children(0);                     contents=e.children(1);                     if (mark.innertext=="+") {                       mark.innertext="-";                       if (contents.classname=="db"||contents.classname=="cb") {                         contents.style.display="block";                       }                       else {                         contents.style.display="inline";                       }                     }                     else if (mark.innertext=="-") {                       mark.innertext="+";                       contents.style.display="none";                     }                   }                   function cl() {                     e=window.event.srcelement;                     if (e.classname!="c") {                       e=e.parentelement;                       if (e.classname!="c") {                         return;                       }                     }                     e=e.parentelement;                     if (e.classname=="e") {                       ch(e);                     }                     if (e.classname=="k") {                       ch2(e);                     }                   }                   function ex(){}                   function h(){window.status=" ";}                   document.onclick=cl;               ]]>           </xsl:comment>         </script>         <style>           body {font:x-small 'verdana'; margin-right:1.5em}           .c  {cursor:pointer}           .b  {color:red; font-family:'courier new'; font-weight:bold;           text-decoration:none}           .e  {margin-left:1em; text-indent:-1em; margin-right:1em}           .k  {margin-left:1em; text-indent:-1em; margin-right:1em}           .t  {color:#990000}           .xt {color:#990099}           .ns {color:red}           .dt {color:green}           .m  {color:blue}           .tx {font-weight:bold}           .db {text-indent:0px; margin-left:1em; margin-top:0px;           margin-bottom:0px;padding-left:.3em;           border-left:1px solid #cccccc; font:small courier}           .di {font:small courier}           .d  {color:blue}           .pi {color:blue}           .cb {text-indent:0px; margin-left:1em; margin-top:0px;           margin-bottom:0px;padding-left:.3em; font:small courier;           color:#888888}           .ci {font:small courier; color:#888888}           pre {margin:0px; display:inline}         </style>       </head>       <body class="st">         <xsl:apply-templates/>       </body>     </html>   </xsl:template>    <xsl:template match="processing-instruction()">     <div class="e">       <span class="b">         <xsl:call-template name="entity-ref">           <xsl:with-param name="name">nbsp</xsl:with-param>         </xsl:call-template>       </span>       <span class="m">         <xsl:text>&lt;?</xsl:text>       </span>       <span class="pi">         <xsl:value-of select="name(.)"/>         <xsl:value-of select="."/>         &#160;       </span>       <span class="m">         <xsl:text>?></xsl:text>       </span>     </div>   </xsl:template>    <xsl:template match="processing-instruction('xml')">     <div class="e">       <span class="b">         <xsl:call-template name="entity-ref">           <xsl:with-param name="name">nbsp</xsl:with-param>         </xsl:call-template>       </span>       <span class="m">         <xsl:text>&lt;?</xsl:text>       </span>       <span class="pi">         <xsl:text>xml </xsl:text>         <xsl:for-each select="@*">           <xsl:value-of select="name(.)"/>           <xsl:text>="</xsl:text>           <xsl:value-of select="."/>           <xsl:text>"&#160;</xsl:text>         </xsl:for-each>       </span>       <span class="m">         <xsl:text>?></xsl:text>       </span>     </div>   </xsl:template>    <xsl:template match="@*">     <span>       <xsl:attribute name="class">         <xsl:if test="xsl:*/@*">           <xsl:text>x</xsl:text>         </xsl:if>         <xsl:text>t</xsl:text>       </xsl:attribute>       <xsl:value-of select="name(.)"/>     </span>     <span class="m">="</span>     <b>       <xsl:value-of select="."/>     </b>     <span class="m">"&#160;</span>   </xsl:template>    <xsl:template match="text()">     <div class="e">       <span class="b"> </span>       <span class="tx">         <xsl:value-of select="."/>       </span>     </div>   </xsl:template>    <xsl:template match="comment()">     <div class="k">       <span>         <a style="visibility:hidden" class="b" onclick="return false"             onfocus="h()">-</a>         <span class="m">           <xsl:text>&lt;!--</xsl:text>         </span>       </span>       <span class="ci" id="clean">         <pre>           <xsl:value-of select="."/>         </pre>       </span>       <span class="b">         <xsl:call-template name="entity-ref">           <xsl:with-param name="name">nbsp</xsl:with-param>         </xsl:call-template>       </span>       <span class="m">         <xsl:text>--></xsl:text>       </span>       <script>f(clean);</script>     </div>   </xsl:template>    <xsl:template match="*">     <div class="e">       <div style="margin-left:1em;text-indent:-2em">         <span class="b">           <xsl:call-template name="entity-ref">             <xsl:with-param name="name">nbsp</xsl:with-param>           </xsl:call-template>         </span>         <span class="m">&lt;</span>         <span>           <xsl:attribute name="class">             <xsl:if test="xsl:*">               <xsl:text>x</xsl:text>             </xsl:if>             <xsl:text>t</xsl:text>           </xsl:attribute>           <xsl:value-of select="name(.)"/>           <xsl:if test="@*">             <xsl:text>&#160;</xsl:text>           </xsl:if>         </span>         <xsl:apply-templates select="@*"/>         <span class="m">           <xsl:text>/></xsl:text>         </span>       </div>     </div>   </xsl:template>    <xsl:template match="*[node()]">     <div class="e">       <div class="c">         <a class="b" href="#" onclick="return false" onfocus="h()">-</a>         <span class="m">&lt;</span>         <span>           <xsl:attribute name="class">             <xsl:if test="xsl:*">               <xsl:text>x</xsl:text>             </xsl:if>             <xsl:text>t</xsl:text>           </xsl:attribute>           <xsl:value-of select="name(.)"/>           <xsl:if test="@*">             <xsl:text> </xsl:text>           </xsl:if>         </span>         <xsl:apply-templates select="@*"/>         <span class="m">           <xsl:text>></xsl:text>         </span>       </div>       <div>         <xsl:apply-templates/>         <div>           <span class="b">             <xsl:call-template name="entity-ref">               <xsl:with-param name="name">nbsp</xsl:with-param>             </xsl:call-template>           </span>           <span class="m">             <xsl:text>&lt;/</xsl:text>           </span>           <span>             <xsl:attribute name="class">               <xsl:if test="xsl:*">                 <xsl:text>x</xsl:text>               </xsl:if>               <xsl:text>t</xsl:text>             </xsl:attribute>             <xsl:value-of select="name(.)"/>           </span>           <span class="m">             <xsl:text>></xsl:text>           </span>         </div>       </div>     </div>   </xsl:template>    <xsl:template match="*[text() , not (comment() or processing-instruction())]">     <div class="e">       <div style="margin-left:1em;text-indent:-2em">         <span class="b">           <xsl:call-template name="entity-ref">             <xsl:with-param name="name">nbsp</xsl:with-param>           </xsl:call-template>         </span>         <span class="m">           <xsl:text>&lt;</xsl:text>         </span>         <span>           <xsl:attribute name="class">             <xsl:if test="xsl:*">               <xsl:text>x</xsl:text>             </xsl:if>             <xsl:text>t</xsl:text>           </xsl:attribute>           <xsl:value-of select="name(.)"/>           <xsl:if test="@*">             <xsl:text> </xsl:text>           </xsl:if>         </span>         <xsl:apply-templates select="@*"/>         <span class="m">           <xsl:text>></xsl:text>         </span>         <span class="tx">           <xsl:value-of select="."/>         </span>         <span class="m">&lt;/</span>         <span>           <xsl:attribute name="class">             <xsl:if test="xsl:*">               <xsl:text>x</xsl:text>             </xsl:if>             <xsl:text>t</xsl:text>           </xsl:attribute>           <xsl:value-of select="name(.)"/>         </span>         <span class="m">           <xsl:text>></xsl:text>         </span>       </div>     </div>   </xsl:template>    <xsl:template match="*[*]" priority="20">     <div class="e">       <div style="margin-left:1em;text-indent:-2em" class="c">         <a class="b" href="#" onclick="return false" onfocus="h()">-</a>         <span class="m">&lt;</span>         <span>           <xsl:attribute name="class">             <xsl:if test="xsl:*">               <xsl:text>x</xsl:text>             </xsl:if>             <xsl:text>t</xsl:text>           </xsl:attribute>           <xsl:value-of select="name(.)"/>           <xsl:if test="@*">             <xsl:text> </xsl:text>           </xsl:if>         </span>         <xsl:apply-templates select="@*"/>         <span class="m">           <xsl:text>></xsl:text>         </span>       </div>       <div>         <xsl:apply-templates/>         <div>           <span class="b">             <xsl:call-template name="entity-ref">               <xsl:with-param name="name">nbsp</xsl:with-param>             </xsl:call-template>           </span>           <span class="m">             <xsl:text>&lt;/</xsl:text>           </span>           <span>             <xsl:attribute name="class">               <xsl:if test="xsl:*">                 <xsl:text>x</xsl:text>               </xsl:if>               <xsl:text>t</xsl:text>             </xsl:attribute>             <xsl:value-of select="name(.)"/>           </span>           <span class="m">             <xsl:text>></xsl:text>           </span>         </div>       </div>     </div>   </xsl:template>    <xsl:template name="entity-ref">     <xsl:param name="name"/>     <xsl:text disable-output-escaping="yes">&amp;</xsl:text>     <xsl:value-of select="$name"/>     <xsl:text>;</xsl:text>   </xsl:template>  </xsl:stylesheet> 


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -