PHP, XSLT and XHTML
All the names appear on an Wiki page - how much nicer would it be to see names flashing instead of numbers? I chatted with Jonathan and he requested a JSON array of strings as input for a new script which would presumably use the numbers as indexes into the array - a minor adjustment.
Creating the array must be almost equally simple I thought. Wiki pages are XHTML. Writing an XSLT to strip the names out of the HTML must be really a simple task. So simple we might as well generalise the problem and solve it for all HTML pages, as there are numerous converters from HTML to XHTML (Pear library). The XSLT was simple to write... but getting it plugged into PHP was well nigh impossible. To make things worse the HTML to XHTML converter in the Pear library didn't produce valid XML in all cases (some tags just weren't closed).
Passing XHTML into the Sablotron XSLT library also did not produce any happy results! Sablotron consistently produced error 69 and refused to continue. Strangely enough, the error message said "unkown encoding'', but in the Sablotron error number list 69 means bad URI or something like that. After checking all the encoding statements, I eventually found a reference to older parsers not understanding the XHTML namespace and not loading the DTD which defines all the encodings, correctly. I had to give up on the PHP solution! My hoster runs PHP 4.3.x and installing new libraries was not an option. PHP + XHTML + XSLT a natural combination one might think. But it had failed.
Instead I just used the XSLT processor on the W3C website - it works just fine!
The script can be run here: http://ekhayaict.com/_gds/gds.php (call it with a parameter xhtml to process other pages)
The XSLT file is here: http://ekhayaict.com/_gds/xslt/gds.xslt
The W3C Transformer is here: http://www.w3.org/2005/08/online_xslt/
Geek Dinner: http://planet.geekdinner.org.za/
February 2nd 2008 08:50