My knowledge of php: blissfully ignorant
My learning curve: monkeySpeed (i.e. a lever lower than ape)
Environment: win2k, apache, php5
Objective: I want to build a system that would basically do this:
XML + XSLT --> html
(Before you go: "search search search you scourge of a newbie" read my stated excuse at one § before the end)
I am trying to use php5 (and its new DOM handler) for this task.
Question: how to best achieve this? Are any of my two [fallowing] suggestions possible? Do You have a better idea?
Now. What I want is to have the url in one html (a processed xml; call it page1.html), when clicked upon (calling the php-processing script), take the user to the next xml document, processed with the xslt, which would output the new html (we can call the php-file for process.php5 set in the core directory with the xslt-file; all future functions would call these files).
I. This is my main idea for the solution, but, how to best achieve this; calling the process.php5 when user clicks on url?
<a href=”http://localhost/index/page2.xml” “<??? php ???>”>page2</a> --> opens page2.html
I.I Note that this tag wouldn't work well in the xslt stylesheet (double use of < <). I have tried to use the new xslt function “php:function()"but then again how would one go about this? It still requires an answer to part I: creating a php-function that would activate itself on a “a href” click.
I.II I tried using the ”form” tag (<form action=”process.php5” method=”post”>page2</form>) with success (surprised). But the use of such a method, for several reasons, isn't desirable.
[INDENT]Update 1!: Thanks to "bpat1424" one can (I needed to change your code a imsy-wimsy-tiny bit though 🙂 ) use this:
<form action="process.php5" method="post" name="form">
<a onClick="document.form.submit();">page2</a>
</form>
This works, however, if I'm not misstaken, it requires javascript? And the issue with I.III still stands... [/INDENT]
I.III Now lets say that applying this idea is possible, then: how would this system work when someone would enter the site from an external url? Would the xml file be processed? It seems to me that the answer to this would be no, which then brings about my second idea for implementing this system:
[INDENT]NOTE: This does seem to work with the ”update 2” entry solution (tried it by linking from one [virtual] host to another)[/INDENT]
II. Is it possible to create a global function that would automatically transform a xml target to html?(i.e. as soon as a “[url]http://.../*.xml[/url] is clicked/activated/loaded anywhere within the entire site the xml file would automatically be transformed to html)
[INDENT]Update 2!: By using a small code and some lines in your .htaccess you can make this happen! (Brett ("bpat1424") deserves some credit for this too )
I got the initial code from: http://www.webpronews.com/webdevelopment/basicdevelopment/wpn-37-20040429HTACCESSWrapperswithPHP.html
And by making some minor tiny-mini-itsy-bitsy changes to it I radically made the code my Bitch.
Add these fallowing lines to your htaccesfile:
AddHandler processXML .xml
Action processXML process.php
(If you have any problems making the code work try writing your full path for the location of your process.php, i.e.:
AddHandler processXML .xml
Action processXML http://localhost/.../process.php
The process.php file should look something like:
<?php
$XMLprocessor = "XMLprocessor.php";
$file = $_SERVER["PATH_TRANSLATED"];
require($XMLprocessor);
?>
The ”XMLprocessor.php is the actual file that will process the XML-data. If you are looking for such a code look up:
If you are using php5+: http://www.zend.com/php5/articles/php5-xmlphp.php
If you are using earlier version of php: http://www.zend.com/zend/tut/tutorial-wong3.php [/INDENT]
I really, really, really do not want to create a *.php5 for every xml that needs to be processed (last desperate resort). And I rather wish to avoid using javascript (but if there is a easy-quick-clean-scheme for making such a function then I'm all ears).
Any alternatives for handling this problem (within the stated environment) are most welcomed.
Any url's to online references would also be most welcomed. Though I want to state for the record that I have ferociously scavenged the Internet for an answer, however, most php / xml tutorials only cover the processing of one xml file, and NOT how to link between several ones. And I haven't found this kind of questions in any articles, forums or FAQ's (which worries me a bit...). I believe I have been using wrong keywords (approach?).
Any answers or even suggestions for handling this problem (maybe you have a better solution?) is graciously appreciated beyond any possible human gratitude.
/