This is a discussion on Editing a Generated XSL file with PHP within the PHP Language forums, part of the PHP Programming Forums category; Hi there Using an XML file containing customer elements: <customers> <customer> <name> bob </...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi there
Using an XML file containing customer elements: <customers> <customer> <name> bob </name> </customer> .... ... </customers> And an XSL file, I have a php file containing java script which takes these 2 files and formats it to display in html table format the customers details. Now: The php file is passed a specific customer name through a URL. I now want to take these 2 files and display the record containing the customer name passed in. This requires changing the XSL code to: <xsl:if test="foo:name='bob'"> <tr> <td><xsl:value-of select= "foo:name"/></td> </tr> But how can I automatically update the XSL file to search for the specific customer name passed in the URL. <xsl:if test="foo:name='PASSED CUSTOMER NAME'"> Is there a way to edit the XSL file through PHP to do this and if so how would I go about doing this. If there isn't a way, what do you think my best solution would be. I am quite new to web technologies so any help would be greatly appreciated! Thanks for your time. Best regards Chris |
|
|||
|
On 13 Dec, 11:56, crazychris...@hotmail.com wrote:
Could you explain this bit: > And an XSL file, I have a php file containing java script which takes > these 2 files and formats it to display in html table format the > customers details. It doesn't make sense? |
|
|||
|
On Dec 13, 1:02 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 13 Dec, 11:56, crazychris...@hotmail.com wrote: > Could you explain this bit:> And an XSL file, I have a php file containing java script which takes > > these 2 files and formats it to display in html table format the > > customers details. > > It doesn't make sense? Sorry, I didn't write that very well. That file is as follows: <html> <head> <script type="text/javascript"> function loadXMLDoc(fname){ var xmlDoc; // code for IE if (window.ActiveXObject){ xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument){ xmlDoc=document.implementation.createDocument(""," ",null); } else{ alert('Your browser cannot handle this script'); } xmlDoc.async=false; xmlDoc.load(fname); return(xmlDoc); } function displayResult(){ xml=loadXMLDoc("CustomerDetails.xml"); xsl=loadXMLDoc("CustomerDetails.xsl"); // code for IE if (window.ActiveXObject){ ex=xml.transformNode(xsl); document.getElementById("example").innerHTML=ex; } // code for Mozilla, Firefox, Opera, etc. else if (document.implementation && document.implementation.createDocument) { xsltProcessor=new XSLTProcessor(); xsltProcessor.importStylesheet(xsl); resultDocument = xsltProcessor.transformToFragment(xml,document); document.getElementById("example").appendChild(res ultDocument); } } </script> </head> <?php echo 'Need to get the Customer name from URL and process'; ?> <body id="example" onLoad="displayResult()"> </body> </html> |
|
|||
|
On 13 Dec, 13:11, crazychris...@hotmail.com wrote:
> On Dec 13, 1:02 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote: > > > On 13 Dec, 11:56, crazychris...@hotmail.com wrote: > > Could you explain this bit:> And an XSL file, I have a php file containing java script which takes > > > these 2 files and formats it to display in html table format the > > > customers details. > > > It doesn't make sense? > > Sorry, I didn't write that very well. That file is as follows: > > <html> > <head> > <script type="text/javascript"> > > function loadXMLDoc(fname){ > var xmlDoc; > // code for IE > if (window.ActiveXObject){ > xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); > } > // code for Mozilla, Firefox, Opera, etc. > else if (document.implementation && > document.implementation.createDocument){ > xmlDoc=document.implementation.createDocument(""," ",null); > } > else{ > alert('Your browser cannot handle this script'); > } > xmlDoc.async=false; > xmlDoc.load(fname); > return(xmlDoc); > > } > > function displayResult(){ > xml=loadXMLDoc("CustomerDetails.xml"); > xsl=loadXMLDoc("CustomerDetails.xsl"); > // code for IE > if (window.ActiveXObject){ > ex=xml.transformNode(xsl); > document.getElementById("example").innerHTML=ex; > } > // code for Mozilla, Firefox, Opera, etc. > else if (document.implementation && > document.implementation.createDocument) { > xsltProcessor=new XSLTProcessor(); > xsltProcessor.importStylesheet(xsl); > resultDocument = xsltProcessor.transformToFragment(xml,document); > document.getElementById("example").appendChild(res ultDocument); > }} > > </script> > </head> > <?php > echo 'Need to get the Customer name from URL and process'; > ?> > <body id="example" onLoad="displayResult()"> > </body> > </html> From what I can see, the php in his file is pointless, you might just as well replace the php section, changing: <?php echo 'Need to get the Customer name from URL and process'; ?> to: Need to get the Customer name from URL and process The only code that you have shown us that actually does anything is javascript. Is there any php that actually "does" something useful? |
|
|||
|
On Dec 13, 2:22 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 13 Dec, 13:11, crazychris...@hotmail.com wrote: > > > > > On Dec 13, 1:02 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote: > > > > On 13 Dec, 11:56, crazychris...@hotmail.com wrote: > > > Could you explain this bit:> And an XSL file, I have a php file containing java script which takes > > > > these 2 files and formats it to display in html table format the > > > > customers details. > > > > It doesn't make sense? > > > Sorry, I didn't write that very well. That file is as follows: > > > <html> > > <head> > > <script type="text/javascript"> > > > function loadXMLDoc(fname){ > > var xmlDoc; > > // code for IE > > if (window.ActiveXObject){ > > xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); > > } > > // code for Mozilla, Firefox, Opera, etc. > > else if (document.implementation && > > document.implementation.createDocument){ > > xmlDoc=document.implementation.createDocument(""," ",null); > > } > > else{ > > alert('Your browser cannot handle this script'); > > } > > xmlDoc.async=false; > > xmlDoc.load(fname); > > return(xmlDoc); > > > } > > > function displayResult(){ > > xml=loadXMLDoc("CustomerDetails.xml"); > > xsl=loadXMLDoc("CustomerDetails.xsl"); > > // code for IE > > if (window.ActiveXObject){ > > ex=xml.transformNode(xsl); > > document.getElementById("example").innerHTML=ex; > > } > > // code for Mozilla, Firefox, Opera, etc. > > else if (document.implementation && > > document.implementation.createDocument) { > > xsltProcessor=new XSLTProcessor(); > > xsltProcessor.importStylesheet(xsl); > > resultDocument = xsltProcessor.transformToFragment(xml,document); > > document.getElementById("example").appendChild(res ultDocument); > > }} > > > </script> > > </head> > > <?php > > echo 'Need to get the Customer name from URL and process'; > > ?> > > <body id="example" onLoad="displayResult()"> > > </body> > > </html> > > From what I can see, the php in his file is pointless, you might just > as well replace the php section, changing: > <?php > echo 'Need to get the Customer name from URL and process'; > ?> > > to: > Need to get the Customer name from URL and process > > The only code that you have shown us that actually does anything is > javascript. Is there any php that actually "does" something useful? Thanks for your response. It is not useful at the moment but if you read to the end of my first post: I now want to be able to pass a specific customer name through a URL thus I will use something like $customerName = $_GET["customerName"]; in php. Using this variable I then want to edit the XSL file so that the generated table will display just the record with that customer name: <xsl:if test="foo:name='$customerName'"> So I want to know if there is "a way to edit the XSL file through PHP to do this and if so how would I go about doing this. If there isn't a way, what do you think my best solution would be" Hope that makes more sense Chris |
|
|||
|
crazychrisy54@hotmail.com <crazychrisy54@hotmail.com> wrote in <d43b4027-7f81-482c-8352-2848e4f3ed6f@e10g2000prf.googlegroups.com>: > On Dec 13, 2:22 pm, Captain Paralytic > <paul_laut...@yahoo.com> wrote: >> On 13 Dec, 13:11, crazychris...@hotmail.com wrote: >> > On Dec 13, 1:02 pm, Captain Paralytic >> > <paul_laut...@yahoo.com> wrote: >> > > On 13 Dec, 11:56, crazychris...@hotmail.com wrote: >> > function displayResult(){ >> > xml=loadXMLDoc("CustomerDetails.xml"); >> > xsl=loadXMLDoc("CustomerDetails.xsl"); >> > // code for IE >> > if (window.ActiveXObject){ >> > ex=xml.transformNode(xsl); >> > document.getElementById("example").innerHTML=ex; >> > } >> > // code for Mozilla, Firefox, Opera, etc. >> > else if (document.implementation && >> > document.implementation.createDocument) { >> > xsltProcessor=new XSLTProcessor(); >> > xsltProcessor.importStylesheet(xsl); >> > resultDocument = >> > xsltProcessor.transformToFragment(xml,document); >> > document.getElementById("example").appendChild(res ultDocument); >> > }} > >> From what I can see, the php in his file is pointless [...] >> The only code that you have shown us that actually does >> anything is javascript. Is there any php that actually >> "does" something useful? > > I now want to be able to pass a specific customer name > through a URL thus I will use something like > $customerName = $_GET["customerName"]; in php. Using this > variable I then want to edit the XSL file so that the > generated table will display just the record with that > customer name: > > <xsl:if test="foo:name='$customerName'"> <http://tinyurl.com/27cro5> -- ....also, I submit that we all must honourably commit seppuku right now rather than serve the Dark Side by producing the HTML 5 spec. |
|
|||
|
On Dec 13, 2:34 pm, Pavel Lepin <p.le...@ctncorp.com> wrote:
> crazychris...@hotmail.com <crazychris...@hotmail.com> wrote > in > <d43b4027-7f81-482c-8352-2848e4f3e...@e10g2000prf.googlegroups.com>:> On Dec 13, 2:22 pm, Captain Paralytic > > <paul_laut...@yahoo.com> wrote: > >> On 13 Dec, 13:11, crazychris...@hotmail.com wrote: > >> > On Dec 13, 1:02 pm, Captain Paralytic > >> > <paul_laut...@yahoo.com> wrote: > >> > > On 13 Dec, 11:56, crazychris...@hotmail.com wrote: > >> > function displayResult(){ > >> > xml=loadXMLDoc("CustomerDetails.xml"); > >> > xsl=loadXMLDoc("CustomerDetails.xsl"); > >> > // code for IE > >> > if (window.ActiveXObject){ > >> > ex=xml.transformNode(xsl); > > document.getElementById("example").innerHTML=ex;>> > } > >> > // code for Mozilla, Firefox, Opera, etc. > >> > else if (document.implementation && > >> > document.implementation.createDocument) { > >> > xsltProcessor=new XSLTProcessor(); > >> > xsltProcessor.importStylesheet(xsl); > >> > resultDocument = > > xsltProcessor.transformToFragment(xml,document); > > document.getElementById("example").appendChild(res ultDocument); > > >> > }} > > >> From what I can see, the php in his file is pointless > > [...] > > >> The only code that you have shown us that actually does > >> anything is javascript. Is there any php that actually > >> "does" something useful? > > > I now want to be able to pass a specific customer name > > through a URL thus I will use something like > > $customerName = $_GET["customerName"]; in php. Using this > > variable I then want to edit the XSL file so that the > > generated table will display just the record with that > > customer name: > > > <xsl:if test="foo:name='$customerName'"> > > <http://tinyurl.com/27cro5> > > -- > ...also, I submit that we all must honourably commit seppuku > right now rather than serve the Dark Side by producing the > HTML 5 spec. Could you help me out a little more please, I am very new to web technologies! |
|
|||
|
crazychrisy54@hotmail.com wrote:
> On Dec 13, 2:22 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote: >> On 13 Dec, 13:11, crazychris...@hotmail.com wrote: >> >> >> >>> On Dec 13, 1:02 pm, Captain Paralytic <paul_laut...@yahoo.com> wrote: >>>> On 13 Dec, 11:56, crazychris...@hotmail.com wrote: >>>> Could you explain this bit:> And an XSL file, I have a php file containing java script which takes >>>>> these 2 files and formats it to display in html table format the >>>>> customers details. >>>> It doesn't make sense? >>> Sorry, I didn't write that very well. That file is as follows: >>> <html> >>> <head> >>> <script type="text/javascript"> >>> function loadXMLDoc(fname){ >>> var xmlDoc; >>> // code for IE >>> if (window.ActiveXObject){ >>> xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); >>> } >>> // code for Mozilla, Firefox, Opera, etc. >>> else if (document.implementation && >>> document.implementation.createDocument){ >>> xmlDoc=document.implementation.createDocument(""," ",null); >>> } >>> else{ >>> alert('Your browser cannot handle this script'); >>> } >>> xmlDoc.async=false; >>> xmlDoc.load(fname); >>> return(xmlDoc); >>> } >>> function displayResult(){ >>> xml=loadXMLDoc("CustomerDetails.xml"); >>> xsl=loadXMLDoc("CustomerDetails.xsl"); >>> // code for IE >>> if (window.ActiveXObject){ >>> ex=xml.transformNode(xsl); >>> document.getElementById("example").innerHTML=ex; >>> } >>> // code for Mozilla, Firefox, Opera, etc. >>> else if (document.implementation && >>> document.implementation.createDocument) { >>> xsltProcessor=new XSLTProcessor(); >>> xsltProcessor.importStylesheet(xsl); >>> resultDocument = xsltProcessor.transformToFragment(xml,document); >>> document.getElementById("example").appendChild(res ultDocument); >>> }} >>> </script> >>> </head> >>> <?php >>> echo 'Need to get the Customer name from URL and process'; >>> ?> >>> <body id="example" onLoad="displayResult()"> >>> </body> >>> </html> >> From what I can see, the php in his file is pointless, you might just >> as well replace the php section, changing: >> <?php >> echo 'Need to get the Customer name from URL and process'; >> ?> >> >> to: >> Need to get the Customer name from URL and process >> >> The only code that you have shown us that actually does anything is >> javascript. Is there any php that actually "does" something useful? > > Thanks for your response. It is not useful at the moment but if you > read to the end of my first post: > > I now want to be able to pass a specific customer name through a URL > thus I will use something like > $customerName = $_GET["customerName"]; in php. Using this variable I > then want to edit the XSL file so that the generated table will > display just the record with that customer name: > > <xsl:if test="foo:name='$customerName'"> > So I want to know if there is > "a way to edit the XSL file through PHP to do this and if so > how would I go about doing this. If there isn't a way, what do you > think my best solution would be" > > Hope that makes more sense > Chris > Chris, First of all, PHP is server side only, not client side. You don't edit an XSL file like you do with a client-side language such as javascript. In fact, you don't want to "edit" the file at all. Rather, you generate the document in PHP and send it to the browser. You can use a template and insert data into the template as required. That way you don't have to regenerate everything with each request. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |