Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $base_path = dirname(__FILE__);
- $suffix = $argv[1];
- if (!in_array($suffix, ['items', 'users', 'offices'])) {
- die ('wrong table');
- }
- $xml_path = $base_path . '/data/an_' . $suffix . '.xml';
- $xsl_path = $base_path . '/xsl/an_' . $suffix . '.xsl';
- $xml_document = new DOMDocument;
- $xsl_document = new DOMDocument;
- //$xml_document->load($xml_path);
- $xsl_document->load($xsl_path);
- $contents = file_get_contents($xml_path);
- $transformed_xml_string = preg_replace_callback('/<\/?[^>]+>/', static function ($m) {
- return strtolower(ltrim(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $m[0]), '_'));
- }, $contents);
- $xml_document->loadXML($transformed_xml_string);
- $xml_document->formatOutput = true;
- $proc = new XSLTProcessor;
- $proc->importStyleSheet($xsl_document); // добавление стилей xsl
- $transformed_xml_string = $proc->transformToXml($xml_document);
- $pretty_printer = new DOMDocument();
- $pretty_printer->loadXML($transformed_xml_string);
- $pretty_printer->formatOutput = true;
- echo $pretty_printer->saveXML();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement