Editing a Generated XSL file with PHP

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 </...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-13-2007
crazychrisy54@hotmail.com
 
Posts: n/a
Default Editing a Generated XSL file with PHP

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
Reply With Quote
  #2 (permalink)  
Old 12-13-2007
Captain Paralytic
 
Posts: n/a
Default Re: Editing a Generated XSL file with PHP

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?
Reply With Quote
  #3 (permalink)  
Old 12-13-2007
crazychrisy54@hotmail.com
 
Posts: n/a
Default Re: Editing a Generated XSL file with PHP

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>
Reply With Quote
  #4 (permalink)  
Old 12-13-2007
Captain Paralytic
 
Posts: n/a
Default Re: Editing a Generated XSL file with PHP

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?
Reply With Quote
  #5 (permalink)  
Old 12-13-2007
crazychrisy54@hotmail.com
 
Posts: n/a
Default Re: Editing a Generated XSL file with PHP

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
Reply With Quote
  #6 (permalink)  
Old 12-13-2007
crazychrisy54@hotmail.com
 
Posts: n/a
Default Re: Editing a Generated XSL file with PHP

Can PHP DOMDocument provide the funcitonality maybe?
Reply With Quote
  #7 (permalink)  
Old 12-13-2007
Pavel Lepin
 
Posts: n/a
Default Re: Editing a Generated XSL file with PHP


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.
Reply With Quote
  #8 (permalink)  
Old 12-14-2007
crazychrisy54@hotmail.com
 
Posts: n/a
Default Re: Editing a Generated XSL file with PHP

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!
Reply With Quote
  #9 (permalink)  
Old 12-14-2007
Jerry Stuckle
 
Posts: n/a
Default Re: Editing a Generated XSL file with PHP

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
==================

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 09:45 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0