1. Let the data and the display separate Test.xml data: Test title Test Content Banner Sidebar main body end of the page Test.xslt templates: test Link rel= "stylesheet" "type=" "Text/css" "href=" "Test.css" "> ]]> 2. The Web page automatically generates a PHP program to read the config file to generate the Target page config file based on the target file name and data file names and template file names specified in the files: test.html test.xml test.xslt PHP Code: Load ("$xsl"); $xmlDoc = new DOMDocument (), $xmlDoc->load ("$xml"); $proc = new Xsltprocessor (), $proc->importstylesheet ($xslDoc), $html = $proc->transformtoxml ($XMLDOC); if (! ( $filehandler = fopen ($name, "w+")) {die ("could not open $name output"), Fwrite ($filehandler, $html); Fclose ($filehandler);} $parser = Xml_parser_create (); Xml_set_element_handler ($parser, "startelement", "endElement"); Xml_set_character_data_handler ($parser, " Characterdata "); if (! ( $filehandler = fopen ($xml _file, "R")) {die (' could not open XML input '),} while ($data = Fread ($filehandler, 4096)) {if (!XM L_parse ($parser, $data, feof ($filehandler))) {Die (sprintf ("XML error:%s @ line%d", Xml_error_string (xml_get_error_ Code ($PARSER)), Xml_get_current_line_number ($parser)));}} Fclose ($filehandler); Xml_parser_free ($parser); foreach ($arr as $sub _arr) {$i = 0;foreach ($sub _arr as $obj) {if ($i = = 0) {$name = $obj;} if ($i = = 1) {$xml = $obj;} if ($i = = 2) {$xsl = $obj;} $i + +;} Buildhtml ($name, $xml, $xsl); }?> 3. Re-planning the entirePage Such a split-style design can make the page more flexible, arbitrarily modify any part of the rest of the block will not affect, and can constantly transform one of the pieces of data such as: Body.xml to generate more new pages, especially suitable for the news system or forum to use Top.xml:
http://www.bkjia.com/PHPjc/486275.html www.bkjia.com true http://www.bkjia.com/PHPjc/486275.html techarticle 1. Let data and display separate Test.xml data: XML titletest title/title contenttest content/content topbanner/top leftsidebar/left Bodymain body/body EndEnd of the Page/end/xml test ...