CHAPTER 13 CASE STUDY: USING PHP (Web hosting comparison) FOR
CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION 397 Let s work through the code in a little more detail. First, the page creates two DomDocument objects for the XML and XSL documents: $xsl = new DomDocument(); $inputdom = new DomDocument(); Then it tests to see if the $city variable is set and includes the appropriate document. The code also loads the related XSLT stylesheet: if (isset($city)) { include ‘mk_weather.php’; $xsl->load(’weather.xsl’); } else { include ‘mk_navxml.php’; $xsl->load(’nav.xsl’); } The next code block loads the XML content and creates a new XsltProcessor: $xml->loadXML($xml->saveXML()); $proc = new XsltProcessor(); The code then imports the stylesheet and applies the transformation, displaying the output in the page: $xsl = $proc->importStylesheet($xsl); $newdom = $proc->transformToDoc($xml); echo $newdom->saveXML(); mk_navxml.php The mk_navxml.php script is a complicated page responsible for much of the work in the application. This page creates the XML document that the application uses for the navigation in the site. The variables passed to the page determine the navigation system. There are four types of navigation to display: 1. The $area variable is set, so the navigation should display the cities. 2. The $country variable is set, so the navigation should display the areas. 3. The $continent variable is set, so the navigation should display the countries. 4. No variables are set, so the navigation should display a list of continents.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.