Example #1
0
/**
 * Metainformation catalogue
 * --------------------------------------------------
 *
 * Lib_XML for MicKa
 *
 * @link       http://www.bnhelp.cz
 * @package    Micka
 * @category   Metadata
 * @version    20121206
 *
 */
function applyTemplate($xmlSource, $xsltemplate)
{
    $rs = FALSE;
    if (File_Exists(CSW_XSL . '/' . $xsltemplate)) {
        if (!extension_loaded("xsl")) {
            if (substr(PHP_OS, 0, 3) == "WIN") {
                dl("php_xsl.dll");
            } else {
                dl("php_xsl.so");
            }
        }
        $xp = new XsltProcessor();
        $xml = new DomDocument();
        $xsl = new DomDocument();
        $xml->loadXML($xmlSource);
        $xsl->load(CSW_XSL . '/' . $xsltemplate);
        $xp->importStyleSheet($xsl);
        //$xp->setParameter("","lang",$lang);
        $xp->setParameter("", "user", $_SESSION['u']);
        $rs = $xp->transformToXml($xml);
    }
    if ($rs === FALSE) {
        setMickaLog('applyTemplate === FALSE', 'ERROR', 'micka_lib_xml.php');
    }
    return $rs;
}
Example #2
0
 function handle($match, $state, $pos, Doku_Handler $handler)
 {
     switch ($state) {
         case DOKU_LEXER_SPECIAL:
             $matches = preg_split('/(&&XML&&\\n*|\\n*&&XSLT&&\\n*|\\n*&&END&&)/', $match, 5);
             $data = "XML: " . $matches[1] . "\nXSLT: " . $matches[2] . "(" . $match . ")";
             $xsltproc = new XsltProcessor();
             $xml = new DomDocument();
             $xsl = new DomDocument();
             $xml->loadXML($matches[1]);
             $xsl->loadXML($matches[2]);
             $xsltproc->registerPHPFunctions();
             $xsltproc->importStyleSheet($xsl);
             $data = $xsltproc->transformToXML($xml);
             if (!$data) {
                 $errors = libxml_get_errors();
                 foreach ($errors as $error) {
                     $data = display_xml_error($error, $xml);
                 }
                 libxml_clear_errors();
             }
             unset($xsltproc);
             return array($state, $data);
         case DOKU_LEXER_UNMATCHED:
             return array($state, $match);
         case DOKU_LEXER_EXIT:
             return array($state, '');
     }
     return array();
 }
Example #3
0
 /**
  * process xsl template with Flow xml
  *
  * @param   string      xsl source file
  * @return  string      xsl transformation output
  */
 public function process($xslfile)
 {
     $flow = Nexista_Flow::Singleton('Nexista_Flow');
     // The following can be used with the NYT xslt cache.
     $use_xslt_cache = "yes";
     if (!is_file($xslfile)) {
         Nexista_Error::init('XSL Handler - Error processing XSL file,
             it is unavailable: ' . $xslfile, NX_ERROR_FATAL);
     }
     if ($use_xslt_cache != "yes" || !class_exists('xsltCache')) {
         $xsl = new DomDocument('1.0', 'UTF-8');
         $xsl->substituteEntities = false;
         $xsl->resolveExternals = false;
         $xslfilecontents .= file_get_contents($xslfile);
         $xsl->loadXML($xslfilecontents);
         $xsl->documentURI = $xslfile;
         $xslHandler = new XsltProcessor();
         $xslHandler->importStyleSheet($xsl);
         if (4 == 3 && function_exists('setProfiling')) {
             $xslHandler->setProfiling("/tmp/xslt-profiling.txt");
         }
     } else {
         $xslHandler = new xsltCache();
         $xslHandler->importStyleSheet($xslfile);
     }
     $output = $xslHandler->transformToXML($flow->flowDocument);
     if ($output === false) {
         Nexista_Error::init('XSL Handler - Error processing XSL file: ' . $xslfile, NX_ERROR_FATAL);
     }
     return $output;
 }
Example #4
0
 /**
  * translate xml
  *
  * @param string $xml_dom 
  * @param string $xsl_dom 
  * @param string $params 
  * @param string $php_functions 
  * @return void
  * @author Andy Bennett
  */
 private static function translate($xml_dom, $xsl_dom, $params = array(), $php_functions = array())
 {
     /* create the processor and import the stylesheet */
     $proc = new XsltProcessor();
     $proc->importStyleSheet($xsl_dom);
     foreach ($params as $name => $param) {
         $proc->setParameter('', $name, $param);
     }
     if (is_array($php_functions)) {
         $proc->registerPHPFunctions($php_functions);
     }
     /* transform and output the xml document */
     $newdom = $proc->transformToDoc($xml_dom);
     return $newdom->saveXML();
 }
 /**
  * Gets all matching XML schema files and loads them into data models for class.
  * @return void
  */
 protected function loadDataModels()
 {
     $ads = array();
     $totalNbTables = 0;
     $this->log('Loading XML schema files...');
     // Get all matched files from schemaFilesets
     foreach ($this->schemaFilesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $srcDir = $fs->getDir($this->project);
         $dataModelFiles = $ds->getIncludedFiles();
         sort($dataModelFiles);
         $defaultPlatform = $this->getGeneratorConfig()->getConfiguredPlatform();
         // Make a transaction for each file
         foreach ($dataModelFiles as $dmFilename) {
             $this->log("Processing: " . $dmFilename, Project::MSG_VERBOSE);
             $xmlFile = new PhingFile($srcDir, $dmFilename);
             $dom = new DomDocument('1.0', 'UTF-8');
             $dom->load($xmlFile->getAbsolutePath());
             // modify schema to include any external schemas (and remove the external-schema nodes)
             $this->includeExternalSchemas($dom, $srcDir);
             // normalize (or transform) the XML document using XSLT
             if ($this->getGeneratorConfig()->getBuildProperty('schemaTransform') && $this->xslFile) {
                 $this->log("Transforming " . $dmFilename . " using stylesheet " . $this->xslFile->getPath(), Project::MSG_VERBOSE);
                 if (!class_exists('XSLTProcessor')) {
                     $this->log("Could not perform XLST transformation. Make sure PHP has been compiled/configured to support XSLT.", Project::MSG_ERR);
                 } else {
                     // normalize the document using normalizer stylesheet
                     $xslDom = new DomDocument('1.0', 'UTF-8');
                     $xslDom->load($this->xslFile->getAbsolutePath());
                     $xsl = new XsltProcessor();
                     $xsl->importStyleSheet($xslDom);
                     $dom = $xsl->transformToDoc($dom);
                 }
             }
             // validate the XML document using XSD schema
             if ($this->validate && $this->xsdFile) {
                 $this->log("  Validating XML using schema " . $this->xsdFile->getPath(), Project::MSG_VERBOSE);
                 if (!$dom->schemaValidate($this->xsdFile->getAbsolutePath())) {
                     throw new EngineException("XML schema file (" . $xmlFile->getPath() . ") does not validate. See warnings above for reasons validation failed (make sure error_reporting is set to show E_WARNING if you don't see any).", $this->getLocation());
                 }
             }
             $xmlParser = new XmlToAppData($defaultPlatform, $this->getTargetPackage(), $this->dbEncoding);
             $xmlParser->setGeneratorConfig($this->getGeneratorConfig());
             $ad = $xmlParser->parseString($dom->saveXML(), $xmlFile->getAbsolutePath());
             $nbTables = $ad->getDatabase(null, false)->countTables();
             $totalNbTables += $nbTables;
             $this->log(sprintf('  %d tables processed successfully', $nbTables), Project::MSG_VERBOSE);
             $ad->setName($dmFilename);
             $ads[] = $ad;
         }
         $this->log(sprintf('%d tables found in %d schema files.', $totalNbTables, count($dataModelFiles)));
     }
     if (empty($ads)) {
         throw new BuildException("No schema files were found (matching your schema fileset definition).");
     }
     foreach ($ads as $ad) {
         // map schema filename with database name
         $this->dataModelDbMap[$ad->getName()] = $ad->getDatabase(null, false)->getName();
     }
     if (count($ads) > 1 && $this->packageObjectModel) {
         $ad = $this->joinDataModels($ads);
         $this->dataModels = array($ad);
     } else {
         $this->dataModels = $ads;
     }
     foreach ($this->dataModels as &$ad) {
         $ad->doFinalInitialization();
     }
     if ($this->validate) {
         foreach ($this->dataModels as $dataModel) {
             $validator = new PropelSchemaValidator($dataModel);
             if (!$validator->validate()) {
                 throw new EngineException(sprintf("The database schema contains errors:\n - %s", join("\n - ", $validator->getErrors())));
             }
         }
     }
     $this->dataModelsLoaded = true;
 }
 public function getXPath($entry, $XSLTfilename = NULL, $fetch_associated_counts = NULL)
 {
     $entry_xml = new XMLElement('entry');
     $data = $entry->getData();
     $fields = array();
     $entry_xml->setAttribute('id', $entry->get('id'));
     //Add date created and edited values
     $date = new XMLElement('system-date');
     $date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('creation_date')), 'created'));
     $date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('modification_date')), 'modified'));
     $entry_xml->appendChild($date);
     //Reflect Workspace and Siteroot params
     $workspace = new XMLElement('workspace', URL . '/workspace');
     $root = new XMLElement('root', URL);
     // Add associated entry counts
     if ($fetch_associated_counts == 'yes') {
         $associated = $entry->fetchAllAssociatedEntryCounts();
         if (is_array($associated) and !empty($associated)) {
             foreach ($associated as $section_id => $count) {
                 $section = SectionManager::fetch($section_id);
                 if ($section instanceof Section === false) {
                     continue;
                 }
                 $entry_xml->setAttribute($section->get('handle'), (string) $count);
             }
         }
     }
     // Add fields:
     foreach ($data as $field_id => $values) {
         if (empty($field_id)) {
             continue;
         }
         $field = FieldManager::fetch($field_id);
         $field->appendFormattedElement($entry_xml, $values, false, null, $entry->get('id'));
     }
     $xml = new XMLElement('data');
     $xml->appendChild($entry_xml);
     $xml->appendChild($workspace);
     $xml->appendChild($root);
     // Build some context
     $section = SectionManager::fetch($entry->get('section_id'));
     $params = new XMLElement('params');
     $params->appendChild(new XMLElement('section-handle', $section->get('handle')));
     $params->appendChild(new XMLElement('entry-id', $entry->get('id')));
     $xml->prependChild($params);
     $dom = new DOMDocument();
     $dom->strictErrorChecking = false;
     $dom->loadXML($xml->generate(true));
     if (!empty($XSLTfilename)) {
         $XSLTfilename = UTILITIES . '/' . preg_replace(array('%/+%', '%(^|/)../%'), '/', $XSLTfilename);
         if (file_exists($XSLTfilename)) {
             $XSLProc = new XsltProcessor();
             $xslt = new DomDocument();
             $xslt->load($XSLTfilename);
             $XSLProc->importStyleSheet($xslt);
             // Set some context
             $XSLProc->setParameter('', array('section-handle' => $section->get('handle'), 'entry-id' => $entry->get('id')));
             $temp = $XSLProc->transformToDoc($dom);
             if ($temp instanceof DOMDocument) {
                 $dom = $temp;
             }
         }
     }
     $xpath = new DOMXPath($dom);
     if (version_compare(phpversion(), '5.3', '>=')) {
         $xpath->registerPhpFunctions();
     }
     return $xpath;
 }
Example #7
0
 function process()
 {
     global $gConf;
     if ('client' == $gConf['xsl_mode']) {
         echo 'depricated';
         exit;
     }
     header($this->_header);
     // xml: string, xsl: file
     if (!($this->_mode & BXXSLTRANSFORM_XML_FILE) && $this->_mode & BXXSLTRANSFORM_XSL_FILE) {
         $args = array('/_xml' => $this->_xml);
         validate_unicode($this->_xml);
         if ((int) phpversion() >= 5) {
             $xml = new DOMDocument();
             if (!@$xml->loadXML($this->_xml)) {
                 $mk = new Mistake();
                 $mk->log("BxXslTransform::process - can not load xml:\n " . $this->_xml);
                 $mk->displayError("[L[Site is unavailable]]");
             }
             $xsl = new DomDocument();
             $xsl->load($this->_xsl);
             $proc = new XsltProcessor();
             $proc->importStyleSheet($xsl);
             $res = $proc->transformToXML($xml);
         } else {
             if (function_exists('domxml_xslt_stylesheet_file')) {
                 $xmldoc = new DomDocument($this->_xml);
                 $xsldoc = domxml_xslt_stylesheet_file($this->_xsl);
                 $result = $xsldoc->process($xmldoc);
                 $res = $xsldoc->result_dump_mem($result);
             } elseif (function_exists('xslt_create')) {
                 $xh = xslt_create();
                 xslt_setopt($xh, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
                 $res = xslt_process($xh, 'arg:/_xml', $this->_xsl, NULL, $args);
                 xslt_free($xh);
             } else {
                 die('Server XSLT support is not enabled, try to use client XSL transformation http://your-domain/orca_folder/?xsl_mode=client');
             }
         }
         return $res;
     }
     // xml: file, xsl: file
     if ($this->_mode & BXXSLTRANSFORM_XML_FILE && $this->_mode & BXXSLTRANSFORM_XSL_FILE) {
         if ((int) phpversion() >= 5) {
             $xml = new DOMDocument();
             $xml->load($this->_xml);
             $xsl = new DomDocument();
             $xsl->load($this->_xsl);
             $proc = new XsltProcessor();
             $proc->importStyleSheet($xsl);
             $res = $proc->transformToXML($xml);
         } else {
             if (function_exists('domxml_xslt_stylesheet_file')) {
                 $xmldoc = new DomDocument($this->_xml);
                 $xsldoc = domxml_xslt_stylesheet_file($this->_xsl);
                 $result = $xsldoc->process($xmldoc);
                 $res = $xsldoc->result_dump_mem($result);
             } elseif (function_exists('xslt_create')) {
                 $xh = xslt_create();
                 $res = xslt_process($xh, $this->_xml, $this->_xsl, NULL, $args);
                 xslt_setopt($xh, XSLT_SABOPT_IGNORE_DOC_NOT_FOUND);
                 xslt_free($xh);
             } else {
                 die('XSLT support is not enabled');
             }
         }
         return $res;
         //return  `/opt/jre1.5.0_06/bin/java -jar /opt/saxon/saxon.jar -ds {$this->_xml} {$this->_xsl}`;
     }
     return "<h1>not supported</h1>";
 }
 /**
  * Uses `DomDocument` to transform the document. Any errors that
  * occur are trapped by custom error handlers, `trapXMLError` or
  * `trapXSLError`.
  *
  * @param XsltProcessor $XSLProc
  *  An instance of `XsltProcessor`
  * @param string $xml
  *  The XML for the transformation to be applied to
  * @param string $xsl
  *  The XSL for the transformation
  * @param array $parameters
  *  An array of available parameters the XSL will have access to
  * @return string
  */
 private function __process(XsltProcessor $XSLProc, $xml, $xsl, array $parameters = array())
 {
     // Create instances of the DomDocument class
     $xmlDoc = new DomDocument();
     $xslDoc = new DomDocument();
     // Set up error handling
     if (function_exists('ini_set')) {
         $ehOLD = ini_set('html_errors', false);
     }
     // Load the xml document
     set_error_handler(array($this, 'trapXMLError'));
     // Prevent remote entities from being loaded, RE: #1939
     $elOLD = libxml_disable_entity_loader(true);
     $xmlDoc->loadXML($xml, LIBXML_NONET | LIBXML_DTDLOAD | LIBXML_DTDATTR | defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0);
     libxml_disable_entity_loader($elOLD);
     // Must restore the error handler to avoid problems
     restore_error_handler();
     // Load the xsl document
     set_error_handler(array($this, 'trapXSLError'));
     // Ensure that the XSLT can be loaded with `false`. RE: #1939
     // Note that `true` will cause `<xsl:import />` to fail.
     $elOLD = libxml_disable_entity_loader(false);
     $xslDoc->loadXML($xsl, LIBXML_NONET | LIBXML_DTDLOAD | LIBXML_DTDATTR | defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0);
     libxml_disable_entity_loader($elOLD);
     // Load the xsl template
     $XSLProc->importStyleSheet($xslDoc);
     // Set parameters when defined
     if (!empty($parameters)) {
         General::flattenArray($parameters);
         $XSLProc->setParameter('', $parameters);
     }
     // Must restore the error handler to avoid problems
     restore_error_handler();
     // Start the transformation
     set_error_handler(array($this, 'trapXMLError'));
     $processed = $XSLProc->transformToXML($xmlDoc);
     // Restore error handling
     if (function_exists('ini_set') && isset($ehOLD)) {
         ini_set('html_errors', $ehOLD);
     }
     // Must restore the error handler to avoid problems
     restore_error_handler();
     return $processed;
 }
 /**
  * Uses `DomDocument` to transform the document. Any errors that
  * occur are trapped by custom error handlers, `trapXMLError` or
  * `trapXSLError`.
  *
  * @param XsltProcessor $XSLProc
  *  An instance of `XsltProcessor`
  * @param string $xml
  *  The XML for the transformation to be applied to
  * @param string $xsl
  *  The XSL for the transformation
  * @param array $parameters
  *  An array of available parameters the XSL will have access to
  * @return string
  */
 private function __process(XsltProcessor $XSLProc, $xml, $xsl, array $parameters = array())
 {
     // Create instances of the DomDocument class
     $xmlDoc = new DomDocument();
     $xslDoc = new DomDocument();
     // Set up error handling
     if (function_exists('ini_set')) {
         $ehOLD = ini_set('html_errors', false);
     }
     // Load the xml document
     set_error_handler(array($this, 'trapXMLError'));
     $xmlDoc->loadXML($xml);
     // Must restore the error handler to avoid problems
     restore_error_handler();
     // Load the xml document
     set_error_handler(array($this, 'trapXSLError'));
     $xslDoc->loadXML($xsl);
     // Load the xsl template
     $XSLProc->importStyleSheet($xslDoc);
     // Set parameters when defined
     if (!empty($parameters)) {
         General::flattenArray($parameters);
         $XSLProc->setParameter('', $parameters);
     }
     restore_error_handler();
     // Start the transformation
     set_error_handler(array($this, 'trapXMLError'));
     $processed = $XSLProc->transformToXML($xmlDoc);
     // Restore error handling
     if (function_exists('ini_set') && isset($ehOLD)) {
         ini_set('html_errors', $ehOLD);
     }
     restore_error_handler();
     return $processed;
 }
Example #10
0
<?php

$processor = new XsltProcessor();
$xsl = new DOMDocument();
$xsl->load("rules.xsl");
$processor->importStyleSheet($xsl);
$xml = new DomDocument();
$xml->load("feed.xml");
$result = $processor->transformToXml($xml);
echo "<pre>{$result}</pre>";
Example #11
0
 static function transform($xsl_file, $xml, $params = null, $charset = 'UTF-8', $nohead = false)
 {
     global $o_global;
     $ent = '<!DOCTYPE page [
     <!ENTITY nbsp   "&#160;">
     <!ENTITY copy   "&#169;">
     <!ENTITY reg    "&#174;">
     <!ENTITY trade  "&#8482;">
     <!ENTITY mdash  "&#8212;">
     <!ENTITY ldquo  "&#0171;">
     <!ENTITY rdquo  "&#0187;">
     <!ENTITY pound  "&#163;">
     <!ENTITY sum    "&#0216;">
     <!ENTITY yen    "&#165;">
     <!ENTITY euro   "&#8364;">
 ]>';
     if (!$nohead) {
         $xml = "<?xml version=\"1.0\" encoding=\"" . $charset . "\"?>\n" . $ent . $xml;
     }
     $browser = null;
     if (empty($xml)) {
         $xml = '<empty_xml>Empty xml</empty_xml>';
     }
     //$xml=iconv('cp1251','cp1251',$xml);
     if (!$nohead && $charset == 'windows-1251') {
         $xml = preg_replace("{[�]}i", "", $xml);
     }
     $xsl = new DomDocument();
     //$xsl->resolveExternals = true;
     $xsl->substituteEntities = true;
     if (file_exists($o_global->themes_site_root . $xsl_file)) {
         $xsl->load($o_global->themes_site_root . $xsl_file);
     } elseif (file_exists($o_global->themes_engine_root . $xsl_file)) {
         $xsl->load($o_global->themes_engine_root . $xsl_file);
     } elseif (_GL_DEBUG === true) {
         return 'Function "transform". Error. File "' . $xsl_file . '" not found (' . $o_global->themes_site_root . $xsl_file . ', ' . $o_global->themes_engine_root . $xsl_file . ')<BR/>' . "\n";
     } else {
         return '';
     }
     //$inputdom = new DomDocument();
     //$inputdom->loadXML($xml);
     /* create the processor and import the stylesheet */
     $proc = new XsltProcessor();
     $proc->registerPhpFunctions();
     //$xsl = $proc->importStylesheet($xsl);
     if ($params) {
         foreach ($params as $key => $value) {
             $proc->setParameter(null, $key, $value);
         }
     }
     $inputdom = new DomDocument();
     $inputdom->substituteEntities = true;
     $inputdom->loadXML($xml);
     $proc->importStyleSheet($xsl);
     $res = $proc->transformToXML($inputdom);
     return $res;
 }
Example #12
0
    if ($format === "lua") {
        $xsl->load('xmltolua-compact.xsl');
        header('Content-Type: text/plain; charset=UTF-8');
    } else {
        if ($format === "json") {
            $xsl->load('xmltojson-compact.xsl');
            header('Content-Type: application/json; charset=UTF-8');
        } else {
            if ($format === "jsonp") {
                $xsl->load('xmltojsonp-compact.xsl');
                header('Content-Type: application/javascript; charset=UTF-8');
            }
        }
    }
}
$xp->importStyleSheet($xsl);
$xp->setParameter('', 'decimalSupported', 'no');
if ($callback && $format === "jsonp") {
    $xp->setParameter('', 'callback', $callback);
}
$xml = new DomDocument();
$contents = file_get_contents($url);
if ($contents) {
    $xml->loadXML($contents);
    if ($xform = $xp->transformToXML($xml)) {
        echo $xform;
    } else {
        trigger_error('XSL transformation failed.', E_USER_ERROR);
    }
} else {
    trigger_error('URL could not be loaded.', E_USER_ERROR);
 /**
  * create google sitemap
  *
  * @return void
  * @author Andy Bennett
  */
 public function google()
 {
     $xsl_path = Kohana::find_file('xsl', 'sitemap', TRUE, 'xsl');
     /* load the xml file and stylesheet as domdocuments */
     $xsl = new DomDocument();
     $xsl->load($xsl_path);
     $inputdom = new DomDocument();
     $inputdom->loadXML($this->sitemap_string);
     /* create the processor and import the stylesheet */
     $proc = new XsltProcessor();
     $proc->importStyleSheet($xsl);
     $proc->setParameter('', 'siteurl', url::base());
     /* transform and output the xml document */
     $newdom = $proc->transformToDoc($inputdom);
     print $newdom->saveXML();
 }
Example #14
0
        $xml->save("xml/site.xml");
        echo $update_value;
        return;
    }
}
// Create instances of the DomDocument class
$xml = new DomDocument();
$xsl = new DomDocument();
$xsltproc = new XsltProcessor();
// Load the xml document and the xsl template
$xml->validateOnParse = true;
$xml->preserveWhiteSpace = true;
$xsl->preserveWhiteSpace = true;
$xml->load("xml/site.xml");
if ($isAdmin == true) {
    $xsl->load("xml/admin.xsl");
} else {
    $xsl->load("xml/online.xsl");
}
// Load the xsl template
$xsltproc->importStyleSheet($xsl);
//Transform to XML in a tempfile and include the result.
//With this method, PHP code embeded in XML is executed.
$tmpfname = tempnam("tmp", $page . "-");
$xsltproc->setParameter('', 'page', $page);
$processed = $xsltproc->transformToURI($xml, $tmpfname);
include $tmpfname;
unlink($tmpfname);
unset($xsltproc);
unset($xsl);
unset($xml);
Example #15
0
 function basemed24LabelAction()
 {
     $pkey = (int) $this->_getParam('pkey');
     $data = array();
     $data['pkey'] = (int) $pkey;
     $data['format'] = 'html';
     $xmlr = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" ?><medication></medication>');
     $n = $xmlr->addChild("data");
     $label = $this->lookupMedLabel($data['pkey']);
     $med = $n->addChild('medicationLabel');
     $doc = new DOMDocument();
     $doc->loadXML($label->asXML());
     $xp = new XsltProcessor();
     $xsl = new DomDocument();
     $xsl->load('/var/www/ch30/chmed/includes/spl-common.xsl');
     $xp->importStyleSheet($xsl);
     $this->view->content = $xp->transformToXML($doc);
 }
 /**
  * Returns all matching XML schema files and loads them into data models for
  * class.
  */
 protected function loadDataModels()
 {
     $schemas = array();
     $totalNbTables = 0;
     $dataModelFiles = $this->getSchemas();
     $defaultPlatform = $this->getGeneratorConfig()->getConfiguredPlatform();
     // Make a transaction for each file
     foreach ($dataModelFiles as $schema) {
         $dmFilename = $schema->getPathName();
         $this->log('Processing: ' . $schema->getFileName());
         $dom = new \DOMDocument('1.0', 'UTF-8');
         $dom->load($dmFilename);
         $this->includeExternalSchemas($dom, $schema->getPath());
         // normalize (or transform) the XML document using XSLT
         if ($this->getGeneratorConfig()->get()['generator']['schema']['transform'] && $this->xsl) {
             $this->log('Transforming ' . $dmFilename . ' using stylesheet ' . $this->xsl->getPath());
             if (!class_exists('\\XSLTProcessor')) {
                 $this->log('Could not perform XLST transformation. Make sure PHP has been compiled/configured to support XSLT.');
             } else {
                 // normalize the document using normalizer stylesheet
                 $xslDom = new \DOMDocument('1.0', 'UTF-8');
                 $xslDom->load($this->xsl->getAbsolutePath());
                 $xsl = new \XsltProcessor();
                 $xsl->importStyleSheet($xslDom);
                 $dom = $xsl->transformToDoc($dom);
             }
         }
         // validate the XML document using XSD schema
         if ($this->validate && $this->xsd) {
             $this->log('  Validating XML using schema ' . $this->xsd->getPath());
             if (!$dom->schemaValidate($this->xsd->getAbsolutePath())) {
                 throw new EngineException(sprintf("XML schema file (%s) does not validate. See warnings above for reasons validation failed (make sure error_reporting is set to show E_WARNING if you don't see any).", $dmFilename), $this->getLocation());
             }
         }
         $xmlParser = new SchemaReader($defaultPlatform, $this->dbEncoding);
         $xmlParser->setGeneratorConfig($this->getGeneratorConfig());
         $schema = $xmlParser->parseString($dom->saveXML(), $dmFilename);
         $nbTables = $schema->getDatabase(null, false)->countTables();
         $totalNbTables += $nbTables;
         $this->log(sprintf('  %d tables processed successfully', $nbTables));
         $schema->setName($dmFilename);
         $schemas[] = $schema;
     }
     $this->log(sprintf('%d tables found in %d schema files.', $totalNbTables, count($dataModelFiles)));
     if (empty($schemas)) {
         throw new BuildException('No schema files were found (matching your schema fileset definition).');
     }
     foreach ($schemas as $schema) {
         // map schema filename with database name
         $this->dataModelDbMap[$schema->getName()] = $schema->getDatabase(null, false)->getName();
     }
     if (count($schemas) > 1 && $this->getGeneratorConfig()->get()['generator']['packageObjectModel']) {
         $schema = $this->joinDataModels($schemas);
         $this->dataModels = array($schema);
     } else {
         $this->dataModels = $schemas;
     }
     foreach ($this->dataModels as &$schema) {
         $schema->doFinalInitialization();
     }
     $this->dataModelsLoaded = true;
 }
 public function google()
 {
     $xsl_path = Kohana::find_file('xsl', 'google_sitemap', TRUE, 'xsl');
     // load the xml file and stylesheet as domdocuments
     $xsl = new DomDocument();
     $xsl->load($xsl_path);
     $inputdom = new DomDocument();
     $inputdom->loadXML($this->sitemap_string);
     // create the processor and import the stylesheet
     $proc = new XsltProcessor();
     $proc->importStyleSheet($xsl);
     $proc->setParameter('', 'siteurl', url::base());
     // transform and output the xml document
     $newdom = $proc->transformToDoc($inputdom);
     $tmp = $newdom->saveXML();
     $tmp = str_replace(' xmlns=""', '', $tmp);
     echo $tmp;
 }
Example #18
0
 function getData($qstr)
 {
     if ($this->cp) {
         $qstr = iconv("UTF-8", $this->cp, $qstr);
     }
     $xp = new XsltProcessor();
     $xml = new DomDocument();
     $xsl = new DomDocument();
     $query["SERVICE"] = "WFS";
     $query["VERSION"] = "1.0.0";
     $query["REQUEST"] = "GetFeature";
     $query["TYPENAME"] = $this->typename;
     $query["Filter"] = "<ogc:Filter><ogc:PropertyIsLike wildCard=\"*\" singleChar=\"@\" escape=\"\\\" matchCase=\"false\"><ogc:PropertyName>" . $this->item . "</ogc:PropertyName><ogc:Literal>{$qstr}</ogc:Literal></ogc:PropertyIsLike></ogc:Filter>";
     $query["Filter"] = urlencode("<Filter><PropertyIsLike wildCard=\"*\" singleChar=\"@\" escape=\"\\\" matchCase=\"false\"><PropertyName>" . $this->item . "</PropertyName><Literal>{$qstr}</Literal></PropertyIsLike></Filter>");
     //highlight_string($query["Filter"]); echo "<hr>";
     $s = $this->getDataByGet($query);
     //highlight_string($s); //exit;
     $xml->loadXML($s);
     $xsl->load($this->xslName);
     $xp->importStyleSheet($xsl);
     return $xp->transformToXML($xml);
 }
 /**
  * Gets all matching XML schema files and loads them into data models for class.
  * @return     void
  */
 protected function loadDataModels()
 {
     $ads = array();
     // Get all matched files from schemaFilesets
     foreach ($this->schemaFilesets as $fs) {
         $ds = $fs->getDirectoryScanner($this->project);
         $srcDir = $fs->getDir($this->project);
         $dataModelFiles = $ds->getIncludedFiles();
         $platform = $this->getGeneratorConfig()->getConfiguredPlatform();
         // Make a transaction for each file
         foreach ($dataModelFiles as $dmFilename) {
             $this->log("Processing: " . $dmFilename);
             $xmlFile = new PhingFile($srcDir, $dmFilename);
             $dom = new DomDocument('1.0', 'UTF-8');
             $dom->load($xmlFile->getAbsolutePath());
             // normalize (or transform) the XML document using XSLT
             if ($this->xslFile) {
                 $this->log("Transforming " . $xmlFile->getPath() . " using stylesheet " . $this->xslFile->getPath(), Project::MSG_VERBOSE);
                 if (!class_exists('XSLTProcessor')) {
                     $this->log("Could not perform XLST transformation.  Make sure PHP has been compiled/configured to support XSLT.", Project::MSG_ERR);
                 } else {
                     // modify schema to include any external schema's (and remove the external-schema nodes)
                     $this->includeExternalSchemas($dom, $srcDir);
                     // normalize the document using normalizer stylesheet
                     $xsl = new XsltProcessor();
                     $xsl->importStyleSheet(DomDocument::load($this->xslFile->getAbsolutePath()));
                     $transformed = $xsl->transformToDoc($dom);
                     $newXmlFilename = substr($xmlFile->getName(), 0, strrpos($xmlFile->getName(), '.')) . '-transformed.xml';
                     // now overwrite previous vars to point to newly transformed file
                     $xmlFile = new PhingFile($srcDir, $newXmlFilename);
                     $transformed->save($xmlFile->getAbsolutePath());
                     $this->log("\t- Using new (post-transformation) XML file: " . $xmlFile->getPath(), Project::MSG_VERBOSE);
                     $dom = new DomDocument('1.0', 'UTF-8');
                     $dom->load($xmlFile->getAbsolutePath());
                 }
             }
             // validate the XML document using XSD schema
             if ($this->validate && $this->xsdFile) {
                 $this->log("Validating XML doc (" . $xmlFile->getPath() . ") using schema file " . $this->xsdFile->getPath(), Project::MSG_VERBOSE);
                 if (!$dom->schemaValidate($this->xsdFile->getAbsolutePath())) {
                     throw new EngineException("XML schema file (" . $xmlFile->getPath() . ") does not validate. See warnings above for reasons validation failed (make sure error_reporting is set to show E_WARNING if you don't see any).", $this->getLocation());
                 }
             }
             $xmlParser = new XmlToAppData($platform, $this->getTargetPackage(), $this->dbEncoding);
             $ad = $xmlParser->parseFile($xmlFile->getAbsolutePath());
             $ad->setName($dmFilename);
             // <-- Important: use the original name, not the -transformed name.
             $ads[] = $ad;
         }
     }
     if (empty($ads)) {
         throw new BuildException("No schema files were found (matching your schema fileset definition).");
     }
     if (!$this->packageObjectModel) {
         $this->dataModels = $ads;
         $this->databaseNames = array();
         // doesn't seem to be used anywhere
         $this->dataModelDbMap = array();
         // Different datamodels may state the same database
         // names, we just want the unique names of databases.
         foreach ($this->dataModels as $dm) {
             $database = $dm->getDatabase();
             $this->dataModelDbMap[$dm->getName()] = $database->getName();
             $this->databaseNames[$database->getName()] = $database->getName();
             // making list of *unique* dbnames.
         }
     } else {
         $this->joinDatamodels($ads);
         $this->dataModels[0]->getDatabases();
         // calls doFinalInitialization()
     }
     $this->dataModelsLoaded = true;
 }
Example #20
0
 function xml2array($xml, $template)
 {
     $xp = new XsltProcessor();
     $xsl = new DomDocument();
     $xsl->load($template);
     $xp->importStyleSheet($xsl);
     $dom = $xp->transformToDoc($xml);
     //--- ladeni ---
     //header('Content-type: application/xml');
     //echo $dom->saveXML(); exit;
     // ---
     $this->xml = $xml;
     //--- vyreseni locales ---
     $locales = $this->xml->getElementsByTagNameNS("http://www.isotc211.org/2005/gmd", "PT_Locale");
     foreach ($locales as $locale) {
         if ($locale->hasAttributes()) {
             $langCode = $locale->getElementsByTagNameNS("http://www.isotc211.org/2005/gmd", "LanguageCode");
             $this->langCodes['#' . $locale->getAttribute('id')] = $langCode->item(0)->getAttribute('codeListValue');
             $this->langCodes[$locale->getAttribute('id')] = $langCode->item(0)->getAttribute('codeListValue');
             // DOCASNE kvuli ruznym chybam ve starych XML
         }
     }
     if ($dom->documentElement) {
         $data = $this->writeNode("", $dom->documentElement, 0);
     }
     if (substr($data, 0, 3) != '$md') {
         return array();
     }
     // pokud jsou prazdne
     $data = str_replace(array("['language'][0]['gco:CharacterString']", "['MD_Identifier']", "ns1:"), array("['language'][0]['LanguageCode']", "['RS_Identifier']", "gco:"), $data);
     //kvuli portalu INSPIRE
     // quick and dirty patch for distance
     $data = str_replace(array("['gco:Distance'][0]['uom']", "['gco:Distance']"), array("['uom'][0]['uomName']", "['value']"), $data);
     // DEBUG
     //echo "<pre>$data</pre>"; exit;
     $data = str_replace(array("gmd:", "gmi:"), "", $data);
     //FIXME udelat pres sablony
     //$data = str_replace("csw:", "", $data); //FIXME udelat pres sablony
     $data = str_replace("'false'", "0", $data);
     $data = str_replace("['language'][0]['gco:CharacterString']", "['language'][0]['LanguageCode']", $data);
     //kvuli portalu INSPIRE
     $elim = array("'gco:CharacterString'", "'gco:Date'", "'gco:DateTime'", "'gco:Decimal'", "'gco:Integer'", "'gco:Boolean'", "'gco:LocalName'", "'URL'", "'gco:Real'", "'gco:Record'", "'gco:RecordType'", "'LocalisedCharacterString'", "gml:", "srv:", "gco:", "['PT_FreeText'][0]", "[][0]", "'DCPList'", "['gts:TM_PeriodDuration'][0]", "['Polygon'][0]['exterior'][0]['LinearRing'][0]['posList'][0]", "'gmx:MimeFileType'");
     $data = str_replace($elim, "", $data);
     $data = str_replace("['serviceType'][0]", "['serviceType'][0]['LocalName'][0]", $data);
     $data = str_replace(array("['begin'][0]['TimeInstant'][0]['timePosition'][0]", "['end'][0]['TimeInstant'][0]['timePosition'][0]", "['MD_Identifier']", "'false'", "'true'", "MI_Metadata"), array("['beginPosition'][0]", "['endPosition'][0]", "['RS_Identifier']", "0", "1", "MD_Metadata"), $data);
     $data = str_replace("['RS_Identifier'][0]['code'][0]['gmx:Anchor'][0]['href'][0]", "['RS_Identifier'][0]['code'][0]", $data);
     //*** pro DC
     $data = str_replace(array("csw:Record", "dc:", "dct:abstract", "[][0]"), array("metadata", "", "description", ""), $data);
     /*if($this->debug)  echo "<pre>". $data . "</pre>"; */
     //---------------------------------------
     if (MICKA_CHARSET != 'UTF-8') {
         $data = iconv('UTF-8', MICKA_CHARSET . '//TRANSLIT', $data);
     }
     //echo "data=".$data;
     eval($data);
     // odstraneni Locale a dateTime
     for ($i = 0; $i < count($md['MD_Metadata']); $i++) {
         unset($md['MD_Metadata'][$i]['locale']);
         if (isset($md['MD_Metadata'][$i]['dateStamp']['@']) && strpos($md['MD_Metadata'][$i]['dateStamp']['@'], 'T')) {
             $pom = explode('T', $md['MD_Metadata'][$i]['dateStamp']['@']);
             // FIXME quick hack
             $md['MD_Metadata'][$i]['dateStamp']['@'] = $pom[0];
         }
         // zpracovani polygonu
         for ($j = 0; $j < count($md['MD_Metadata'][$i]['identificationInfo'][0]['MD_DataIdentification'][0]['extent'][0]['EX_Extent'][0]['geographicElement']); $j++) {
             if ($md['MD_Metadata'][$i]['identificationInfo'][0]['MD_DataIdentification'][0]['extent'][0]['EX_Extent'][0]['geographicElement'][$j]['EX_BoundingPolygon'][0]['polygon'][0]['@']) {
                 $geom = explode(" ", $md['MD_Metadata'][$i]['identificationInfo'][0]['MD_DataIdentification'][0]['extent'][0]['EX_Extent'][0]['geographicElement'][$j]['EX_BoundingPolygon'][0]['polygon'][0]['@']);
                 $result = "";
                 for ($k = 0; $k < count($geom); $k = $k + 2) {
                     if ($result) {
                         $result .= ",";
                     }
                     $result .= $geom[$k] . " " . $geom[$k + 1];
                 }
                 $md['MD_Metadata'][$i]['identificationInfo'][0]['MD_DataIdentification'][0]['extent'][0]['EX_Extent'][0]['geographicElement'][$j]['EX_BoundingPolygon'][0]['polygon'][0]['@'] = "MULTIPOLYGON(((" . $result . ")))";
             }
         }
         // doplnění překladu INSPIRE
         // --- multiligvalni klic. slova
         $lang = $md['MD_Metadata'][$i]["language"][0]["LanguageCode"][0]['@'];
         if (!$lang) {
             $lang = 'eng';
         }
         if ($md['MD_Metadata'][$i]['identificationInfo'][0]['SV_ServiceIdentification']) {
             $this->multiKeywords($md['MD_Metadata'][$i]['identificationInfo'][0]['SV_ServiceIdentification'][0]['descriptiveKeywords'], $lang);
         } else {
             $this->multiKeywords($md['MD_Metadata'][$i]['identificationInfo'][0]['MD_DataIdentification'][0]['descriptiveKeywords'], $lang);
         }
     }
     //var_dump($md);
     return $md;
 }