473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

XSLT in Mozilla using parameters

Hi all,

I'm working on an a clientside xslt using jscript that passes a parameter to the xsl. I've got it working no problem in IE but cant get it to work in Mozilla. Can anyone help?

This is my IE code -

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <head>
  3.       <title>CEL Learning</title>
  4.  
  5.     <script language="JScript">
  6.         <!--
  7.         //Applies the XSLT transformation and returns a string
  8.         //containing transformed text
  9.         function applyXSLT(xmlFileName, xslFileName)
  10.         {
  11.             var objXML;
  12.             var objXSLT;
  13.  
  14.             objXML = new ActiveXObject("MSXML2.DOMDocument.3.0");
  15.             objXML.async = false;
  16.             objXML.validateOnParse = false;
  17.  
  18.             objXSLT = new ActiveXObject("MSXML2.DOMDocument.3.0");
  19.             objXSLT.async = false;
  20.             objXSLT.validateOnParse = false;
  21.  
  22.             try
  23.             {    
  24.                 //Load XML and XSLT documents
  25.                 objXML.load(xmlFileName);
  26.                 objXSLT.load(xslFileName);
  27.  
  28.                 return objXML.transformNode(objXSLT)
  29.  
  30.             }
  31.             catch(e)
  32.             {
  33.                 //error handling
  34.             }
  35.         }
  36.  
  37.         //Applies the XSLT transformation and returns a string
  38.         //containing transformed text
  39.         //Allows passing a single parameter to the stylesheet
  40.         function applyXSLTWithParam(xmlFileName, xslFileName, paramName, paramValue)
  41.         {
  42.             var objXML;
  43.             var objXSLT;
  44.             var objxsltTemplate;
  45.             var objxsltProcessor;
  46.  
  47.             try
  48.             {    
  49.                 objXML = new ActiveXObject("MSXML2.DOMDocument.3.0");
  50.                 objXML.async = false;
  51.                 objXML.validateOnParse = false;
  52.  
  53.                 objXSLT = new ActiveXObject("MSXML2.FreeThreadedDOMDocument.3.0");
  54.                 objXSLT.async = false;
  55.                 objXSLT.validateOnParse = false;
  56.  
  57.                 //Load XML and XSLT documents
  58.                 objXML.load(xmlFileName);
  59.                 objXSLT.load(xslFileName);
  60.  
  61.                 objxsltTemplate = new ActiveXObject("MSXML2.XSLTemplate.3.0");
  62.                 objxsltTemplate.stylesheet = objXSLT;
  63.                 objxsltProcessor = objxsltTemplate.createProcessor();
  64.                 objxsltProcessor.input = objXML;
  65.                 objxsltProcessor.addParameter(paramName, paramValue);
  66.  
  67.                 objxsltProcessor.transform();
  68.  
  69.                 return objxsltProcessor.output;
  70.             }
  71.             catch(e)
  72.             {
  73.                 //error handling
  74.             }
  75.         }
  76.  
  77.         function GetEmpList()
  78.         {
  79.             lessonList.innerHTML = applyXSLT("topic.xml", "EmpForHTML1.xsl");
  80.         }
  81.  
  82.         function showEmpDetails(pageID)
  83.         {
  84.             lessonContents.innerHTML = applyXSLTWithParam("topic.xml", "EmpForHTML2.xsl", "pageID", pageID);
  85.         }
  86.  
  87.         -->
  88.     </script>
  89. </head>
  90. <body onload="GetEmpList();">
  91.  
  92.  
  93. <table width="780" border="2">
  94. <tr height="60">
  95. <td><img src="nalspec.gif" alt="NALSpec" /></td>
  96. <td>&nbsp;&nbsp</td>
  97. <td><img src="cel.gif" alt="CEL" /></td>
  98. </tr>
  99.  
  100.  
  101. <tr height="350">
  102. <td colspan="3" ><div id="lessonContents" /></td>
  103. </tr>
  104. <tr height="40">
  105. <td><div id="lessonList" /></td>
  106. <td>&nbsp;&nbsp</td>
  107. <td><img src="footer.gif" alt="footer" /></td>
  108. </tr>
  109. </table>
  110.  
  111.  
  112. </body>
  113. </html>
  114.  
This is as far as i've got with the Mozilla version but cant get it workin

Expand|Select|Wrap|Line Numbers
  1.  
  2. <html>
  3.     <head>
  4.       <title>CEL Learning</title>
  5.  
  6.     <script language="JScript">
  7.  
  8.         //Applies the XSLT transformation and returns a string
  9.         //containing transformed text
  10.         function applyXSLT(xmlFileName, xslFileName)
  11.         {
  12.  
  13.            oXmlDom.load(xmlFileName);
  14.            oXslDom.load(xslFileName);
  15.  
  16.  
  17.            var oResultDom = oProcessor.transformToDocument(oXmlDom);
  18.  
  19.            return oResultDom;
  20.            }
  21.  
  22.          //Applies the XSLT transformation and returns a string
  23.         //containing transformed text
  24.         //Allows passing a single parameter to the stylesheet
  25.         function applyXSLTWithParam(xmlFileName, xslFileName, paramName, paramValue)
  26.         {
  27.            oXmlDom.load(xmlFileName);
  28.            oXslDom.load(xslFileName);
  29.  
  30.            var oProcessor = new XSLTProcessor()
  31.            oProcessor.importStylesheet(oXslDom);
  32.            oProcessor.setParameter(null, paramName, paramValue);
  33.  
  34.            var oResultDom = oProcessor.transformToDocument(oXmlDom);
  35.  
  36.            return oResultDom;
  37.  
  38.         }
  39.  
  40.         function GetEmpList()
  41.         {
  42.             lessonList.innerHTML = applyXSLT("topic.xml", "EmpForHTML1.xsl");
  43.         }
  44.  
  45.         function showEmpDetails(pageID)
  46.         {
  47.             lessonContents.innerHTML = applyXSLTWithParam("topic.xml", "EmpForHTML2.xsl", "pageID", pageID);
  48.         }
  49.  
  50.         -->
  51.     </script>
  52. </head>
  53. <body onload="GetEmpList();">
  54.  
  55.  
  56. <table width="780" border="2">
  57. <tr height="60">
  58. <td><img src="nalspec.gif" alt="NALSpec" /></td>
  59. <td>&nbsp;&nbsp</td>
  60. <td><img src="cel.gif" alt="CEL" /></td>
  61. </tr>
  62.  
  63.  
  64. <tr height="350">
  65. <td colspan="3" ><div id="lessonContents" /></td>
  66. </tr>
  67. <tr height="40">
  68. <td><div id="lessonList" /></td>
  69. <td>&nbsp;&nbsp</td>
  70. <td><img src="footer.gif" alt="footer" /></td>
  71. </tr>
  72. </table>
  73.  
  74.  
  75. </body>
  76. </html>
  77.  
  78.  
Nov 5 '07 #1
2 3083
jkmyoung
2,057 Expert 2GB
I'm not experienced enough to directly answer your question, but have you tried Sarissa instead? Cross browser javascript, to work with both IE and Firefox.

http://dev.abiss.gr/sarissa/howtos.html#transform
http://dev.abiss.gr/sarissa/jsdoc/XS...l#setParameter
Nov 5 '07 #2
Cheers for the suggestion i finally got it working heres the solution if anyones interested.

Expand|Select|Wrap|Line Numbers
  1. var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined'); 
  2.         var ie = (typeof window.ActiveXObject != 'undefined');
  3.  
  4. function applyXSLWithParam(xmlFile, xslFile, paramName, paramValue){
  5.             if(moz){
  6.                 //create doc to hold xml file and load xml to it
  7.                 var xmlDoc = document.implementation.createDocument("", "", null);
  8.                 xmlDoc.async = false;
  9.                 xmlDoc.load(xmlFile);
  10.  
  11.                 //create doc to hold xsl and load it to doc
  12.                 var xslDoc = document.implementation.createDocument("", "", null);
  13.                 xslDoc.async = false;
  14.                 xslDoc.load(xslFile);
  15.  
  16.                 // process created docs
  17.                 var xsltProc = new XSLTProcessor();
  18.                 xsltProc.importStylesheet(xslDoc);
  19.                 //pass parameter
  20.                 xsltProc.setParameter(null, paramName, paramValue);
  21.                 var resultDoc = xsltProc.transformToDocument(xmlDoc);
  22.  
  23.                 //serialise output to string
  24.                 var xmlSerial = new XMLSerializer;
  25.                 Content = xmlSerial.serializeToString(resultDoc);
  26.             }
  27.             else if (ie){    
  28.                 objXML = new ActiveXObject("MSXML2.DOMDocument.3.0");
  29.                 objXML.async = false;
  30.                 objXML.validateOnParse = false;
  31.  
  32.                 objXSLT = new ActiveXObject("MSXML2.FreeThreadedDOMDocument.3.0");
  33.                 objXSLT.async = false;
  34.                 objXSLT.validateOnParse = false;
  35.  
  36.                 //Load XML and XSLT documents
  37.                 objXML.load(xmlFile);
  38.                 objXSLT.load(xslFile);
  39.  
  40.                 objxsltTemplate = new ActiveXObject("MSXML2.XSLTemplate.3.0");
  41.                 objxsltTemplate.stylesheet = objXSLT;
  42.                 objxsltProcessor = objxsltTemplate.createProcessor();
  43.                 objxsltProcessor.input = objXML;
  44.                 objxsltProcessor.addParameter(paramName, paramValue);
  45.                 objxsltProcessor.transform();
  46.  
  47.                 Content = objxsltProcessor.output;
  48.             }
  49.         return Content;
  50.         }
  51.  
  52.  
Nov 8 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Jeff Rubard | last post by:
I am curious to know whether anyone has experience using XSLT for web XML (non-XHTML) styling, either with CSS or standalone. I myself have engaged in rather unsuccessful experiments with the...
1
by: David | last post by:
I would like to be able to re-sort data in an HTML table on the without returning to the server. It seems like an XSLT should be able to accomplish this, but I can't find enough information... ...
1
by: Claudio Jolowicz | last post by:
I need to produce an HTML page with javascript using XSLT. Unfortunately, Mozilla has a bug that lets it crash when it encounters document.write in an XSLT stylesheet (bugzilla# 202765). Are there...
4
by: Stephen | last post by:
I have the following that outputs an xml file to a div using ajax: <script type="text/javascript"> function ajaxXML(url,control_id){ if (document.getElementById) { var x =...
7
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID...
4
by: Philipp Reiss | last post by:
Hello group, I'm new in this topic and I run into problems where google can't help me. I have a XML-file, wich is bound to a XSLT-file, and this works fine in a browser. How do I show the same...
4
by: nickjtew | last post by:
Hi, I need to change the output made by my xsl file depending on what ID is passed by the user in the browser. The user will need to click links, eg, http://xxx.com/blah.xml?articleid=245 ...
3
by: RC | last post by:
Let's say: if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) { // Now I got an XML object here var xmlDocument = XMLHttpRequestObject.responseXML; // next I have...
4
by: th1421 | last post by:
Hi, I'm new to FireFox. I am currently trying to convert my website to be compatible with it. Doing so I’m trying to process some XML/XSLT pages (preferably without using JavaScript). When I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.