Advertisement
fagci

xmlpipe.php

Nov 18th, 2020
826
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.07 KB | None | 0 0
  1. <?php
  2.  
  3. $base_path = dirname(__FILE__);
  4.  
  5. $suffix = $argv[1];
  6.  
  7. if (!in_array($suffix, ['items', 'users', 'offices'])) {
  8.     die ('wrong table');
  9. }
  10.  
  11. $xml_path = $base_path . '/data/an_' . $suffix . '.xml';
  12. $xsl_path = $base_path . '/xsl/an_' . $suffix . '.xsl';
  13.  
  14. $xml_document = new DOMDocument;
  15. $xsl_document = new DOMDocument;
  16.  
  17. //$xml_document->load($xml_path);
  18. $xsl_document->load($xsl_path);
  19.  
  20. $contents = file_get_contents($xml_path);
  21.  
  22. $transformed_xml_string = preg_replace_callback('/<\/?[^>]+>/', static function ($m) {
  23.     return strtolower(ltrim(preg_replace('/[A-Z]([A-Z](?![a-z]))*/', '_$0', $m[0]), '_'));
  24. }, $contents);
  25. $xml_document->loadXML($transformed_xml_string);
  26.  
  27. $xml_document->formatOutput = true;
  28.  
  29. $proc = new XSLTProcessor;
  30. $proc->importStyleSheet($xsl_document); // добавление стилей xsl
  31.  
  32. $transformed_xml_string = $proc->transformToXml($xml_document);
  33.  
  34.  
  35. $pretty_printer = new DOMDocument();
  36. $pretty_printer->loadXML($transformed_xml_string);
  37. $pretty_printer->formatOutput = true;
  38.  
  39.  
  40. echo $pretty_printer->saveXML();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement