diff --git a/aufgabe2/print.inc.php b/aufgabe2/print.inc.php index ffaf151..8381860 100644 --- a/aufgabe2/print.inc.php +++ b/aufgabe2/print.inc.php @@ -1,7 +1,15 @@ saveXML($parser->parseCSV($csv_file)); + +if ($result) { + $parser->printXML('world_data.xml', 'resources/world_data_sheet.xslt'); + + // TODO: display table +} else { + echo "Failed saving xml file"; +} \ No newline at end of file diff --git a/aufgabe2/resources/world_data_sheet.xslt b/aufgabe2/resources/world_data_sheet.xslt new file mode 100644 index 0000000..36d47ea --- /dev/null +++ b/aufgabe2/resources/world_data_sheet.xslt @@ -0,0 +1,46 @@ + + + + + +

World Data Overview ...

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
idnamebirth_rate_per_1000cell_phones_per_100children_per_womanelectricity_consumption_per_capitagdp_per_capitagdp__per__capita__growthinflation_annualinternet_user_per_100life_expectancymilitary_expenditure_percent_of_gdpgps_latgps_long
+ + +
+
\ No newline at end of file diff --git a/aufgabe2/world_data_parser.php b/aufgabe2/world_data_parser.php index c4e7224..ad84bc0 100644 --- a/aufgabe2/world_data_parser.php +++ b/aufgabe2/world_data_parser.php @@ -22,8 +22,10 @@ class WorldDataParser { } function saveXML($data) { - if (file_exists("world_data.xml")) { - unlink("world_data.xml"); + $file = 'world_data.xml'; + + if (file_exists($file)) { + unlink($file); } $xml = '' . PHP_EOL; @@ -48,10 +50,28 @@ class WorldDataParser { } $xml .= ''. PHP_EOL; - $file = 'world_data.xml'; file_put_contents($file, $xml); - return file_exists("world_data.xml"); + return file_exists($file); + } + function printXML($xml_file, $xslt_sheet) { + $xsl_doc = new DOMDocument(); + $xsl_res = $xsl_doc->loadXML($xslt_sheet); + if ($xsl_res === false) { + echo "reading xsl sheet failed: {$xsl_res}"; + return; + } + + $xml_doc = new DOMDocument(); + if ($xml_doc->loadXML($xml_file) === false) { + echo "reading world data xml failed"; + return; + } + + $xsl = new XSLTProcessor(); + + $xsl->importStyleSheet($xsl_doc); + echo $xsl->transformToXML($xml_doc); } } \ No newline at end of file