logo of blechtrottel.net blechtrottel.net
deutsch

XSLT in PHP4

Introduction

With PHP5 you get SimpleXML, a rather simple and reliable tool for turning XML into HTML and others. Affordable webspace more often than not comes with PHP4 support only. So all you are left with is XSLT.

What good is XSLT anyway? Well, XML did - after early enthusiasm - not really make it in the internet as a replacement for HTML. Most of the time it is applied on backends on servers, but one variety is present on almost every of today's important websites - RSS.

RSS newsfeeds need special software to be read. Most browsers nowadays can display RSS readably via hidden menu entries or through add-ons. But the average visitor to one's website cannot or does not want to deal with these - let alone newsreader programs.

boring RSS in a browser
boring: RSS in the original

Challenge

So how can you make information available to everyone without having to maintain separate pages with the same content? In theory you can link the RSS file to an XSL stylesheet - in the real world browsers support these transformations poorly, if at all. Thus you are left with beautifying RSS with CSS, a rather poor option.

little improvement: with CSS
little improvement: with CSS

Yet this news page can be generated in PHP via XSLT from the RSS, which spares you the trouble of typing all news twice. In PHP5, as mentioned above, that is quite simple and well documented; but in PHP4 most of the functions needed are deemed experimental and thus poorly documented and not widely available. But don't worry: blechtrottel brodaktschns have got the knack :-)

Preliminaries

These instructions expect you to have some basic knowledge of PHP, XML and XSL; we will only deal with the PHP aspects here. Should you be interested in the XSL we use for RSS 2.0 you can download and study the stylesheet blechtrottel brodaktschns use.

Page 1 - Page 2 - Page 3 - Page 4