Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your XSLT is using <code>xsl:include</code> you might receive weird unexplainable errors but always with the same end result: your transformation failing. </p> <p>See this chromium bug report and please support it! <a href="http://code.google.com/p/chromium/issues/detail?id=8441" rel="noreferrer">http://code.google.com/p/chromium/issues/detail?id=8441</a></p> <p>The bug is actually in webkit though. For more info <a href="http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XSLT/Q_24311395.html" rel="noreferrer">here's</a> another link which goes into more detail why it doesn't work.</p> <p>The only way around this is to pre-process the stylesheet so that it injects the included stylesheets. Which is what a crossbrowser XSLT library like Sarissa will do for you automatically.</p> <p>If your looking for jQuery solution:<br> <a href="http://plugins.jquery.com/project/Transform/" rel="noreferrer">http://plugins.jquery.com/project/Transform/</a> is a cross browser XSL plug-in. I've succesfully used this to get <code>xsl:include</code> working in the past without much hassle. You don't have to rewrite your xsl's this plugin will pre-process them for you. Definitely worth looking at as it's more lightweight then Sarissa.</p> <p><strong>UPDATE:</strong></p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script language="javascript" src="jquery-1.3.2.min.js"&gt;&lt;/script&gt; &lt;script language="javascript" src="jquery.transform.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function loadXML(file) { var xmlDoc = null; try //Internet Explorer { xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.load(file); } catch(e) { try //Firefox, Mozilla, Opera, etc. { xmlDoc=document.implementation.createDocument("","",null); xmlDoc.async=false; xmlDoc.load(file); } catch(e) { try //Google Chrome { var xmlhttp = new window.XMLHttpRequest(); xmlhttp.open("GET",file,false); xmlhttp.send(null); xmlDoc = xmlhttp.responseXML.documentElement; } catch(e) { error=e.message; } } } return xmlDoc; } function xslTransform(xmlObject, xslObject) { try { $("body").append("&lt;div id='test'&gt;&lt;/div&gt;"); var a = $("#test").transform({ xmlobj: xmlObject, xslobj: xslObject }); } catch (exception) { if (typeof (exception) == "object" &amp;&amp; exception.message) alert(exception.message); else alert(exception); } } var xmlObject = loadXML("input.xml"); var xslObject = loadXML("transform.xsl"); $(document).ready(function() { xslTransform(xmlObject, xslObject); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>This test html page works both in Chrome/FireFox/IE. </p> <p>input.xml is just a simple xml file containing <code>&lt;root /&gt;</code> transform.xsl is the stripped down xsl you posted.</p> <p><strong>EDIT</strong> </p> <p>It does however seem the $.transform has problems importing stylesheets from included files:</p> <p>Here's how to fix this:</p> <p>Locate </p> <pre><code>var safariimportincludefix = function(xObj,rootConfig) { </code></pre> <p>in <code>jquery.transform.js</code> and replace the entire function with this:</p> <pre><code>var safariimportincludefix = function(xObj,rootConfig) { var vals = $.merge($.makeArray(xObj.getElementsByTagName("import")),$.makeArray(xObj.getElementsByTagName("include"))); for(var x=0;x&lt;vals.length;x++) { var node = vals[x]; $.ajax({ passData : { node : node, xObj : xObj, rootConfig : rootConfig}, dataType : "xml", async : false, url : replaceref(node.getAttribute("href"),rootConfig), success : function(xhr) { try { var _ = this.passData; xhr = safariimportincludefix(xhr,_.rootConfig); var imports = $.merge(childNodes(xhr.getElementsByTagName("stylesheet")[0],"param"),childNodes(xhr.getElementsByTagName("stylesheet")[0],"template")); var excistingNodes = []; try { var sheet = _.xObj; var params = childNodes(sheet,"param"); var stylesheets = childNodes(sheet,"template"); existingNodes = $.merge(params,stylesheets); } catch(exception) { var x = exception; } var existingNames = []; var existingMatches = []; for(var a=0;a&lt;existingNodes.length;a++) { if(existingNodes[a].getAttribute("name")) { existingNames[existingNodes[a].getAttribute("name")] = true; } else { existingMatches[existingNodes[a].getAttribute("match")] = true; } } var pn = _.node.parentNode; for(var y=0;y&lt;imports.length;y++) { if(!existingNames[imports[y].getAttribute("name")] &amp;&amp; !existingMatches[imports[y].getAttribute("match")]) { var clonednode = _.xObj.ownerDocument.importNode(imports[y],true); //pn.insertBefore(clonednode,_.xObj); pn.insertBefore(clonednode,childNodes(_.xObj,"template")[0]); } } pn.removeChild(_.node); } catch(ex) { } } }); } return xObj; }; </code></pre> <p>Now using the previously pasted test index.html use this for <code>transform.xsl</code>:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt; &lt;xsl:include href="include.xsl" /&gt; &lt;xsl:output method="html"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:call-template name="giveMeAnIncludedHeader" /&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>And this for <code>include.xsl</code></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template name="giveMeAnIncludedHeader"&gt; &lt;h1&gt;Test&lt;/h1&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>With the previously posted fix in <code>jquery.transform.js</code> this will now insert the included <code>&lt;h1&gt;Test&lt;/h1&gt;</code> on all the browsers.</p> <p>You can see it in action here: <a href="http://www.mpdreamz.nl/xsltest" rel="noreferrer">http://www.mpdreamz.nl/xsltest</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload