Let's see a screenshot of what the result of this transform would look like.
The image below is the result of reading a "live" XML document from
the web instead of the sample shown above, after all having up- to-date news
can be fun while testing out the XSL transforms.
Looks kinda cool, doesn't it ?!, there's so much more you can do with XML/XSLT
but I'll leave that for you to research. We could even write an XSL transformation
that generates documents viewable by PDA's and Cellular phones.
Let me focus on the code used to do this transform (after all this article
is supposed to be about PHP).
I wrote a class to wrap the Sablotron functions in keeping with good OOP practises.
Here is the script that uses the class. By looking at the code it becomes obvious
why using PHP Objects is a good idea and can simplify web development.
// 30.07.2000 by Justin Grant
In the script, the XSLTransformer class file is included.
I define the URL to the XML document and file path to the XSL document.
I then create an instance of the transformer class.
If I can successfully load the XSL document then I try and load the XML document.
If these documents are successfully loaded then the transform is performed and
the result is written out to the browser.
If loading one or both of these documents is unsuccessful then I just write
out the error message property of the object.
Finally in good OOP style I destroy the object because I'm done with it. It's
that simple !