Jump to content

john6384

Members
  • Posts

    24
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

john6384's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Solved - put a function in main JS file that so that element is populated.
  2. I think that it is to do with the order that my code executes i.e. element has not been populated or assigned anything before it is used - this gives an empty. To solve this I tried to make the whole of the code shown a function that is called after another function is used to setup the page - point of this was to make element not empty. This did not work - please suggest how I can debug this or any other ideas.
  3. I am trying to set a parameter in my XSL to be a PHP variable that I know is working as it can be seen using an alert in the AJAX. Element keeps coming through as empty - javascript error. Any more code, explanation needed then please say. Cheers var username = '<?php echo $username;?>'; var myXMLHTTPRequest = new XMLHttpRequest(); var myXSLTProcessor = new XSLTProcessor(); alert(username); //load the XSL file myXMLHTTPRequest.open("GET", "mnu.xsl", false); myXMLHTTPRequest.send(null); //get the XML document xslStylesheet = myXMLHTTPRequest.responseXML; myXSLTProcessor.importStylesheet(xslStylesheet); //load the xml file myXMLHTTPRequest.open("GET", "mnu.xml", false); myXMLHTTPRequest.send(null); var xmlSource = myXMLHTTPRequest.responseXML; alert(myXMLHTTPRequest.responseText); myXSLTProcessor.setParameter(null, "username", username); fragment = myXSLTProcessor.transformToFragment(xmlSource, document); var element = document.getElementById("menuTarget"); while(element.firstChild) { element.removeChild(element.firstChild); } element.appendChild(fragment);
  4. Well this function was given to me but I dont think its complete and also it gives back in the alert in the AJAX - query was empty. function SQLFromXML($doc){ global $sqlString; //Initialize the XML parser $parser=xml_parser_create(); //Function to use at the start of an element function start($parser,$element_name,$element_attrs) { global $sqlString; $sqlString="insert into " . $element_name . "("; $seperator=""; foreach ($element_attrs as $key => $value) { $sqlString=$sqlString . $seperator . $key; $seperator=","; } $sqlString=$sqlString . ") values("; $seperator=""; foreach ($element_attrs as $key => $value) { $sqlString=$sqlString . $seperator . "'" . $value . "'"; $seperator=","; } $sqlString=$sqlString . ")"; } //Function to use at the end of an element function stop($parser,$element_name) { // echo "<br />"; } //Function to use when finding character data function char($parser,$data) { // echo $data; } //Specify element handler xml_set_element_handler($parser,"start","stop"); //Specify data handler xml_set_character_data_handler($parser,"char"); //parse data xml_parse($parser,$doc); //Free the XML parser xml_parser_free($parser); return $sqlString; } Any comments on why this is returned in the alert? Cheers
  5. Hello, first of all I have some AJAX that POST's a PHP files output like so: //XMLResults is a string of XML ... XMLResults += '/>'; var objHTTP, strResult; objHTTP=new XMLHttpRequest(); objHTTP.open('POST', "PutData.php", false); objHTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); objHTTP.overrideMimeType('text/html'); objHTTP.send("xml=" + xmlDoc); strResult=objHTTP.responseText; Now in PutData.php I need to convert from XML to SQL. What is the best way of doing this? I have this to get the data from the POST: foreach($_POST as $key => $data){ mysql_query(SQLFromXML($data)) or die (mysql_error()); } Then I will need a function to do the work - please describe the structure of this and give any hints or point me to code. Thankyou
  6. All I need is to know the appropriate function for the xsltProcessor.
  7. I need to use xsltProcessor to set a variable to something. What xsltProcessor function would I use - the below does not work? var item = document.getElementById("descriptionInput"); xmlDoc = myXMLHTTPRequest.responseXML; var search = xsltProcessor.transformToFragment(xmlDoc, document); myDOM = search; document.getElementById("XMLDiv").innerHTML = search; I want to make search an xsltprocessor variable with value of item. Thank you John
  8. I made some progress in using XSL variables. This code gives an error in IE - error: object expected line 6 char 1 http://127.0.0.1/buglist.xml?descriptionInput=ateststring <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <xsl:variable name="isPriority" select="2"></xsl:variable> <html> <head> <title></title> <script language="javascript"> <![CDATA[ var XSLStylesheet; var XSLTProcessor = new XSLTProcessor(); var xmlhttp = new XMLHttpRequest(); var XMLDOM; function descriptionSearchFunction(){ ID = document.getElementById("descriptionInput").innerHTML; alert("ID2"); if(window.ActiveXObject){ XMLDOM = new ActiveXObject('Msxml2.FreeThreadedDOMDocument'); XMLDOM.async = false; XMLDOM.loadXML("buglist.xml"); XSLTDOM = new ActiveXObject('Msxml2.FreeThreadedDOMDocument'); XSLTDOM.async = false; XSLTDOM.load("BugList.xsl"); XSLStylesheet = new ActiveXObject('Msxml2.XSLTemplate'); XSLStylesheet.stylesheet = XSLTDOM; XSLTProcessor = XSLStylesheet.createProcessor(); XSLTProcessor.input = XMLDOM; XSLTProcessor.addParameter('isPriority', ID); XSLTProcessor.transform(); } //If mozilla browser else if(window.XMLHttpRequest){ xmlhttp.onreadystatechange = state_Change xmlhttp.open("GET","buglist.xml",false) xmlhttp.send(null) } try{ content.innerHTML=XSLTProcessor.output; } catch(e){ document.open(); document.write(XSLTProcessor.output); document.close(); } } function state_Change() { // if xmlhttp shows "loaded" if (xmlhttp.readyState==4) { // if "OK" if (xmlhttp.status==200) { document.getElementById('XMLDiv').innerHTML = xmlhttp.responseText; } else { alert("Problem retrieving XML data"); } } } ]]> </script> </head> <body> <form name='descriptionSearchForm'> <input type='text' name='descriptionInput' id='descriptionInput' onsubmit='descriptionSearchFunction()'></input> </form> <div id="XMLDiv"> </div> <table id="buglist" style="border:1px solid black" height= "400" width="1000"> <tr><td>ID</td><td>Priority</td><td>Description</td></tr> <xsl:for-each select="buglist/bug"> <tr> <xsl:choose> <xsl:when test="IsPriority>=$isPriority"> <td><xsl:value-of select="ID"/></td> <td><xsl:value-of select="IsPriority"/></td> <td><xsl:value-of select="Description"/></td> </xsl:when> <xsl:otherwise> <td><xsl:value-of select="ID"/></td> <td><xsl:value-of select="IsPriority"/></td> <td bgcolor="#ff00ff"><xsl:value-of select="Description"/></td> </xsl:otherwise> </xsl:choose> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Cheers anyone
  9. Well im almost there when using IE but not in Firefox. I understand the code that uses an activeXObject although I do not understand how to do this for XMLHTTPRequest. Some clues please: <script language="javascript"> <![CDATA[ var XSLStylesheet; var XSLTProcessor = new XSLTProcessor(); var XMLDOM; function descriptionSearchFunction(xmlfile,xslfile){ ID = document.getElementById("descriptionInput").innerHTML; if(window.ActiveXObject){ XMLDOM = new ActiveXObject('Msxml2.FreeThreadedDOMDocument'); XMLDOM.async = false; XMLDOM.loadXML(xmlfile); XSLTDOM = new ActiveXObject('Msxml2.FreeThreadedDOMDocument'); XSLTDOM.async = false; XSLTDOM.load(xslfile); XSLStylesheet = new ActiveXObject('Msxml2.XSLTemplate'); XSLStylesheet.stylesheet = XSLTDOM; XSLTProcessor = XSLStylesheet.createProcessor(); XSLTProcessor.input = XMLDOM; XSLTProcessor.addParameter('ID', ID); XSLTProcessor.transform(); }else if(window.XMLHttpRequest){ var myXMLHTTPRequest = new XMLHttpRequest(); myXMLHTTPRequest.open("GET", xslfile, false); myXMLHTTPRequest.send(null); var xslRef = myXMLHTTPRequest.responseXML; XSLTProcessor.importStylesheet(xslRef); xmlhttp.open("GET",xmlfile,true); xmlhttp.send(null); } try{ content.innerHTML=XSLTProcessor.output; } catch(e){ document.open(); document.write(XSLTProcessor.output); document.close(); } } ]]> </script> Only clues as I do not learn when the code is written for me. Cheers
  10. Thanks for the reply. I need to use xsltProcessor in order to make a variable in the XSL file that changes i.e: <?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="/"> <html> <head> <title></title> <script language="javascript"> <![CDATA[ var xslStylesheet; var xsltProcessor = new XSLTProcessor(); var myDOM; var xmlDoc; var ID = "1"; function descriptionSearchFunction(){ var myXMLHTTPRequest = new XMLHttpRequest(); myXMLHTTPRequest.open("GET", "BugList.xsl", false); myXMLHTTPRequest.send(null); xslStylesheet = myXMLHTTPRequest.responseXML; xsltProcessor.importStylesheet(xslStylesheet); myXMLHTTPRequest = new XMLHttpRequest(); myXMLHTTPRequest.open("GET", "buglist.xml", false); myXMLHTTPRequest.send(null); xmlDoc = myXMLHTTPRequest.responseXML; var fragment = xsltProcessor.transformToFragment(xmlDoc, document); ID = document.getElementById("descriptionInput").innerHTML; myXSLTProcessor.addParameter('ID', ID); myDOM = fragment; document.getElementById("descriptionInput").appendChild(fragment); } ]]> </script> </head> <body> <form name='descriptionSearchForm'> <input type='text' name='descriptionInput' id='descriptionInput' onkeyup='descriptionSearchFunction()'></input> </form> <table id="buglist"> <xsl:for-each select="buglist/bug"> <tr> <td><xsl:value-of select="if (ID != '') then ID > $ID else '5'"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet> Is the select if else statement correct? - is the syntax correct for checking if ID is nothing. Also if you spot any other reason for this not working then please say. Cheers
  11. Hello, how would use a variable in an XSLT document that changes when a textfield is changed i.e I need an HTML field to filter the XML displayed by changing the XSLT. So far I have the XML displayed and know how to change it using XSLT. Also I have a Javascript function that detects a keypress in the HTML textfield. Problem is how do I update XSLT with javascript or is this the wrong way. The desired effect as you can guess is to have a search textfield that dynamically filters the XML. Only want CLUES for this please and im using a forum as a last resort and becasue of lack of time. Thank you
  12. That did it - cheers mate. Solved.
  13. I am populating a drop down list from mysql DB using PHP. Then javascript changes a tables content below according to the value selected. Problem is I want it to have the last option chosen when the tables is loaded (refreshed). Any more explantion then please say. <script language="javascript" type="text/javascript" > function jumpto(formIn) { var form = formIn; form = form.users.options[form.users.options.selectedIndex].value; self.location='BugList.php?userName=' + form; } </script>
  14. Could not update user on database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`Initials`='MBs' `Pass`='michelle' `Email`='michelle@aol.com' WHERE `ID`=10' at line 1 Thats the error I get now. Cheers for reply though.
  15. I am trying to run this query although I get this error: //Assign the query $query = "UPDATE webusers SET Name='$name' Initials='$initials' Pass='$password' Email='$email' WHERE ID=$ID"; //Execute query $result = mysql_query($query); if(!$result){ die("Could not update user on database: <br />".mysql_error()); } Could not update user on database: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(ID=11 Name='Doug' Initials='DB' Pass='pass' Email='doug@aol.com') WHERE ID=11' at line 1 The syntax looks fine. Please help and give reasons for this. Cheers
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.