Note that there are some explanatory texts on larger screens.

plurals
  1. POChrome and Safari XSLT using JavaScript
    primarykey
    data
    text
    <p>I have the following code that applies a XSLT style </p> <pre><code>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 &amp;&amp; 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); } } </code></pre> <p>The code is working in IE and firefox but not in Chrome and Safari. Any ideas why?</p> <p><strong>Update</strong></p> <pre><code>ResultDocument = xsltProcessor.transformToFragment(xml, document); </code></pre> <p>The line above is returning null. No error is being thrown.</p> <p><strong>Update</strong></p> <p>The code is not working as the xslt file contains xsl:include. Need to find a way to get the include working I will paste progress here</p> <p><strong>Update</strong></p> <p>It has been recomended that I use the <a href="http://plugins.jquery.com/project/Transform/" rel="noreferrer">http://plugins.jquery.com/project/Transform/</a> plugin. I am trying to use the client side libary as the example of include works here (<a href="http://daersystems.com/jquery/transform/" rel="noreferrer">http://daersystems.com/jquery/transform/</a>).</p> <p>The code works in IE but still not in chrome.</p> <pre><code>Test.Xml.xslTransform = function(xml, xsl) { try { $("body").append("&lt;div id='test' style='display:none;'&gt;&lt;/div&gt;"); 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); } } } </code></pre> <p>xml and xsl are both objects being passed in.</p> <p><strong>Update</strong></p> <p>I tried changing the XSL file to being something very simple with no include and Chrome is still not applying the stylesheet and IE is. The XSL that is being brought in as an object is:</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" 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/" &gt; &lt;xsl:output method="html"/&gt; &lt;xsl:template match="/"&gt; &lt;h1&gt;test&lt;/h1&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>Update</strong></p> <p>The end result that I want is for the xsl to be applied to the xml file. The xsl file has in it includes. I want the trasnfer to happen on the client ideally.</p> <p><strong>Updated</strong> <em>Rupert could you update the question with the xml and how you're calling Test.Xml.xslTransform ?</em></p> <p>I got the xml using ie8</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;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"&gt;&lt;soap:Body&gt;&lt;SearchListItemsResponse xmlns="http://schemas.microsoft.com/sharepoint/soap/"&gt;&lt;SearchListItemsResult&gt;&lt;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"&gt; &lt;rs:data ItemCount="1"&gt; &lt;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"/&gt; &lt;/rs:data&gt; &lt;/listitems&gt;&lt;/SearchListItemsResult&gt;&lt;/SearchListItemsResponse&gt;&lt;/soap:Body&gt;&lt;/soap:Envelope&gt; </code></pre> <p>The code is being called as follows:</p> <pre><code>xsl = Test.Xml.loadXMLDoc("/_layouts/xsl/xsl.xslt"); var doc = Test.Xml.xslTransform(xData.responseXML, xsl); </code></pre> <p>xData is the xml returned by a web service.</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.
 

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