Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem in executing XSLT transform file in XUL JavaScript
    primarykey
    data
    text
    <p>I'm working on XUL and i'm trying to execute XSLT processor function in XUL using JavaScript.</p> <p>I have JavaScript function where I'm can update new record to my XML file and save the XML file. After that I'm trying to execute the XSLT processor function but I couldn't load my XSL and XML file.</p> <p>My working environment is in windows using Eclipse, XulBooster. Generally, to load any file I use ("File://C:/mercredi.xml") or ("C:/mercredi.xml"); both file path works fine in other functions even in the JavaScript function which I used the same file path to read and save the XML file.</p> <p>1.I have copied the following code Listing6: from this website:<br> <a href="http://www.ibm.com/developerworks/xml/library/x-ffox3/index.html" rel="nofollow">http://www.ibm.com/developerworks/xml/library/x-ffox3/index.html</a></p> <pre><code>function process() { //Create an XSLT processor instance var processor = new XSLTProcessor(); //Create an empty XML document for the XSLT transform var transform = document.implementation.createDocument("", "", null); //Load the XSLT transform.onload = loadTransform; transform.load("file://C:/idgenerator.xsl"); //Triggered once the XSLT document is loaded function loadTransform(){ //Attach the transform to the processor processor.importStylesheet(transform); source = document.implementation.createDocument("", "", null); source.load("file://C:/mercredi.xml"); source.onload = runTransform; } //Triggered once the source document is loaded function runTransform(){ //Run the transform, creating a fragment output subtree that //can be inserted back into the main page document object (given //in the second argument) var frag = processor.transformToFragment(source, document); } } </code></pre> <p>Then I checked Mozilla website and followed the instructions, still I couldn't load my file. 2.The following code is copied from this website: <a href="https://developer.mozilla.org/en/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations" rel="nofollow">https://developer.mozilla.org/en/Using_the_Mozilla_JavaScript_interface_to_XSL_Transformations</a></p> <p>Even in this function I couldn't load my XML file.</p> <pre><code>function xslt() { var processor = new XSLTProcessor(); var testTransform = document.implementation.createDocument("", "test", null); // just an example to get a transform into a script as a DOM // XMLDocument.load is asynchronous, so all processing happens in the // onload handler testTransform.addEventListener("load", onload, false); testTransform.load("file://C:/mercredi.xml"); function onload() { processor.importStylesheet(testTransform); } } </code></pre> <p>This is my JavaScript code to execute the process() function of XSLT processor.</p> <pre><code>function saveFile(output, savefile) { //function from http://puna.net.nz/archives/Code/Mozilla%20XUL%20LOG%20-%20read%20local%20files%20and%20write%20local%20files.htm //var savefile = "c:\\mozdata.txt"; try { netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } catch (e) { alert("Permission to save file was denied."); } var file = Components.classes["@mozilla.org/file/local;1"] .createInstance(Components.interfaces.nsILocalFile); file.initWithPath( savefile ); if ( file.exists() == false ) { alert( "File Updated Successfully "); file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 ); } var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"] .createInstance( Components.interfaces.nsIFileOutputStream ); /* Open flags #define PR_RDONLY 0x01 #define PR_WRONLY 0x02 #define PR_RDWR 0x04 #define PR_CREATE_FILE 0x08 #define PR_APPEND 0x10 #define PR_TRUNCATE 0x20 #define PR_SYNC 0x40 #define PR_EXCL 0x80 */ /* ** File modes .... ** ** CAVEAT: 'mode' is currently only applicable on UNIX platforms. ** The 'mode' argument may be ignored by PR_Open on other platforms. ** ** 00400 Read by owner. ** 00200 Write by owner. ** 00100 Execute (search if a directory) by owner. ** 00040 Read by group. ** 00020 Write by group. ** 00010 Execute by group. ** 00004 Read by others. ** 00002 Write by others ** 00001 Execute by others. ** */ outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 ); var result = outputStream.write( output, output.length ); outputStream.close(); alert( "File Updated Successfully "); clear(); process(); } </code></pre> <p>Why I want to execute to XSLT file in my XUL? is to generate a unique ID for my customer in the XML file.</p> <p>Please help me What am I doing wrong here?!? Thank you very much.</p> <p>This is my XSLT file:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output method="xml" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="CONTACT"&gt; &lt;xsl:copy&gt; &lt;Customer-Id&gt; &lt;xsl:value-of select="generate-id(.)"/&gt; &lt;/Customer-Id&gt; &lt;xsl:copy-of select="FirstName|LastName|gmail|yahoo| Hotmail |URL|Facebook-ID"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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