Lecture 17
Side remark: for-each equivalence again Second-hand cars Item Model Engine Size Price </ thead>
Conditional processing In essence, conditional processing is already provided by the select and match attributes However, XSLT also provides two construct for explicitly specifying conditional processing: the xsl:if element and xsl:choose element The xsl:if element
Example usage of the xsl:if element Second-hand cars Item Model Engine Size Price =2500">Too expensive
Conditional processing (contd.) Format of the xsl:choose element Format of the xsl:when and xsl:otherwise elements
Example usage of the xsl:choose element Second-hand cars Item Model Engine Size Price = 2500">Too expensive
Calling templates by name Second-hand cars Item Model Engine Size Price Unlike xsl:apply-templates, xsl:call-template does not change the current node or the current node list
Passing parameter values to named templates Second-hand cars Item Model Engine Size Price
A note on generating XML from PHP
The Usual situation in PHP By default, a PHP programmer does not have to generate headers for the HTTP responses that his programs generate –The PHP run-time system does this for him –It assumes that he is generating HTML Thus, the headers it generates include the following Content-Type: text/html
Example PHP program The text that is generated look like XML But the header that will precede this text in the response message will be Content-Type: text/html Thus, the browser will treat the response body as if it were a HTML file and will simply ignore the unrecognizable tags
Corrected PHP program The header that will precede this text in the response message will be Content-Type: application/xml The browser will treat the response body as if it were an XML file
Server-side use of XSL stylesheets
Example PHP program The program below applies the stylesheet in carStyleSheet.xsl to the XML file in cars.xml and sends the resultant output to the browser which sent a HTTP request to the PHP program <?php $parser = xslt_create(); $html = xslt_process($parser, 'cars.xml','carStyleSheet.xsl'); xslt_free($parser); echo $html; ?>