412 CHAPTER 13 CASE STUDY: USING PHP (Jetty web server)

412 CHAPTER 13 CASE STUDY: USING PHP FOR AN XML APPLICATION The application also adds the outlook to the document. Because the code sorts the query in reverse count order, it displays the first record, which contains the highest number of responses: $outlook = $xml->createElement(’outlook’, $wrow[’weatherType’]); $outlook = $root->appendChild($outlook); As the page finishes with the weather report, it can output the available weather types. You ve seen this code before: $types = $xml->createElement(’weathertypes’); $types = $root->appendChild($types); $sql = ‘SELECT weatherTypeID, weatherType FROM weatherType’; $tRes = mysql_query($sql) or die(mysql_error() . “n
” . $sql); while ($tRow = mysql_fetch_array($tRes)) { $type = $xml->createElement(’type’, $tRow[’weatherType’]); $type->setAttribute(’id’, $tRow[’weatherTypeID’]); $type = $types->appendChild($type); } } weather.xsl The application needs to transform the XML content using the XSLT stylesheet weather.xsl. The stylesheet starts in the following way: It then checks that there are weather results by counting the number of temperature elements and storing the value in a variable: The value is 1 if users have entered a forecast, and 0 if there are no database results. The stylesheet can then test to see if an error occurred:

Error

If there is an error, the stylesheet displays the details; otherwise, it displays the weather title:

Weather for

Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

Leave a Reply