The XML file is your key file where dynamic data is stored, changed or removed. It does not affect any the layout of the pages themselves. This you should already know. After looking at the above code and from your experience working with XSL to transform XML files to HTML output, you are probably saying to yourself this is not worth it.
I agree with you one hundred percent, not only is it a lot of work; but also requires you add to your skill set XSL and XML. In fact, if there is no requirement to output the data to anything but a regular browser it might be in your best interest to simply stick to PHP and HTML. But if you are going to support other devices or media you should seriously consider using PHP and XSL.
The following three XSL transformations will demonstrate this, the technologies used will be WML, cHTML and VXML,
It is unlikely you will have the voice-recognition technology equipment to run the VXML example. However, you can visit one of the VoiceXML providers such as VoiceGenie.com or Tellme.com. As well in this demonstration the output will stream the entire information from start to finish. When developing VoiceXML applications you should tailor the application towards voice interaction.
In this example, it would probably be better to list out the titles of the books in menu like fashion, possible as abbreviated titles. From there the user should select an option and thereafter the details of the book would be told to the user. The implementation of this is beyond the scope of this article.
Because we are using the same content in all cases, whether it is HTML, WML, cHTML or VXML the same XML data file is used. If additional books are added, books need to be removed or changes need to be made such as sales price all you really have to do is change the data in the XML file. As well this provides another layer of abstraction between the presentation layer and server-side code.
It keeps your code a lot cleaner rather then having several different files or several if statements in your PHP code to output the appropriate content for the appropriate viewer. As well it prevents you from inserting difficult to find and difficult to debug PHP code in all the different files for all the different devices being supported.
However, you will notice the Sale price is only displayed based upon the if statement in the XSL stylesheet, if this for some reason needed to be changed you would have to make the change in each XSL stylesheet. To avoid this, simply generate dynamic XML files with PHP and have your logic in the PHP code determine what goes into the XML file.
As well you can then use PHP to determine which appropriate pre-defined XSL stylesheet to use. This way your XML files are purely used as means of holding data in meaningful structure without any processing logic at all.
Furthermore, you have not only saved maintenance time but as well reduced the amount of effort needed if you were to support other features such as:
• Reports in PDF format • RSS feeds • WebServices • SVG • ChessML • AvantGo • AIML • XHTML • HDML
the list goes on and on.
Web Services is especially important when you want to start sharing the same information to other businesses or simply to other devices that are not script based such as SymbianOS devices, Palm, J2ME enabled devices and SmartPhones. This is because you are working with an agreed upon industry standard largely based on XML.