Download presentation
Presentation is loading. Please wait.
1
Lecture 17
2
Side remark: for-each equivalence again Second-hand cars Item Model Engine Size Price </ thead>
3
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
4
Example usage of the xsl:if element Second-hand cars Item Model Engine Size Price =2500">Too expensive
5
Conditional processing (contd.) Format of the xsl:choose element Format of the xsl:when and xsl:otherwise elements
6
Example usage of the xsl:choose element Second-hand cars Item Model Engine Size Price = 2500">Too expensive
7
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
8
Passing parameter values to named templates Second-hand cars Item Model Engine Size Price
9
A note on generating XML from PHP
10
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
11
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
12
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
13
Server-side use of XSL stylesheets
14
Server-side processing in PHP The implementation of server-side XSLT processing changed when PHP5 was introduced We will look at two approaches –PHP4 approach –PHP5 approach
15
Example PHP4 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; ?>
16
Example PHP5 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 $xml_filename=“cars.xml"; $xsl_filename=“carStyleSheet.xsl"; $xmldoc = new DOMDocument(); $xmldoc->load($xml_filename); $xsldoc = new DOMDocument(); $xsldoc->load($xsl_filename); $xsl = new XsltProcessor(); $xsl->importStyleSheet($xsldoc); echo $xsl->transformToXML($xmldoc); ?>
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.