Exemplo n.º 1
0
 protected function _processTransform(DomDocument $domDocument, DomDocument $xslTemplate)
 {
     $this->_processor->importStylesheet($xslTemplate);
     $transformedXml = $this->_processor->transformToXml($domDocument);
     $transformedXml = str_replace(array("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", "<?xml version=\"1.0\"?>\n"), '', $transformedXml);
     return $transformedXml;
 }
Exemplo n.º 2
0
 /**
  * Simple, dynamic xsl transform
  */
 protected function transform($xml, $path_to_xsl, $output_type = null, array $params = array(), array $import_array = array(), $to_string = true)
 {
     if ($path_to_xsl == "") {
         throw new \Exception("no stylesheet supplied");
     }
     // make sure we have a domdocument
     if (is_string($xml)) {
         $xml = Parser::convertToDOMDocument($xml);
     }
     // create xslt processor
     $processor = new \XsltProcessor();
     $processor->registerPhpFunctions();
     // add parameters
     foreach ($params as $key => $value) {
         $processor->setParameter(null, $key, $value);
     }
     // add stylesheet
     $xsl = $this->generateBaseXsl($path_to_xsl, $import_array, $output_type);
     $processor->importStylesheet($xsl);
     // transform
     if ($to_string == true) {
         return $processor->transformToXml($xml);
     } else {
         return $processor->transformToDoc($xml);
     }
 }
Exemplo n.º 3
0
 /**
  * Render the table.
  *
  * @param mixed $tableDom
  * @param mixed $config
  */
 public function render(Document $reportDom, Config $config)
 {
     $template = $config['template'];
     $out = $config['file'];
     if (!file_exists($template)) {
         throw new \RuntimeException(sprintf('XSLT template file "%s" does not exist', $template));
     }
     $stylesheetDom = new \DOMDocument('1.0');
     $stylesheetDom->load($template);
     $xsltProcessor = new \XsltProcessor();
     $xsltProcessor->importStylesheet($stylesheetDom);
     $xsltProcessor->setParameter(null, 'title', $config['title']);
     $xsltProcessor->setParameter(null, 'phpbench-version', PhpBench::VERSION);
     $xsltProcessor->setParameter(null, 'date', date('Y-m-d H:i:s'));
     $output = $xsltProcessor->transformToXml($reportDom);
     if (!$output) {
         throw new \InvalidArgumentException(sprintf('Could not render report with XSL file "%s"', $template));
     }
     if (null !== $out) {
         file_put_contents($out, $output);
         $this->output->writeln('Dumped XSLT report:');
         $this->output->writeln($out);
     } else {
         $this->output->write($output);
     }
 }
Exemplo n.º 4
0
 /**
  * Simple XSLT transformation function
  * 
  * @param mixed $xml			DOMDocument or string containing xml
  * @param string $strXsltPath	Relative file path to xslt document. Will look in both library location and 
  * 								local app location for documents, and combine them so local overrides library 
  * 								templates, if neccesary. 
  * @param array $arrParams		[optional] array of parameters to pass to stylesheet
  * @param bool $bolDoc			[optional] return result as DOMDocument (default false)
  * @param array $arrInclude		[optional] additional stylesheets that should be included in the transform
  * @return mixed				newly formatted document as string or DOMDocument
  * @static 
  */
 public static function transform($xml, $strXsltPath, $arrParams = null, $bolDoc = false, $arrInclude = array())
 {
     if ($strXsltPath == "") {
         throw new Exception("no stylesheet supplied");
     }
     if (is_string($xml)) {
         // load xml document from string
         $objXml = new DOMDocument();
         $objXml->loadXML($xml);
         $xml = $objXml;
     }
     $objXsl = self::generateBaseXsl($strXsltPath, $arrInclude);
     // create XSLT Processor
     $objProcessor = new XsltProcessor();
     $objProcessor->registerPhpFunctions();
     if ($arrParams != null) {
         // add in parameters
         foreach ($arrParams as $key => $value) {
             $objProcessor->setParameter(null, $key, $value);
         }
     }
     // transform
     $objXsl = $objProcessor->importStylesheet($objXsl);
     if ($bolDoc == true) {
         return $objProcessor->transformToDoc($xml);
     } else {
         return $objProcessor->transformToXml($xml);
     }
 }
Exemplo n.º 5
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;
}
 public function xhtmlAction()
 {
     $xml = DOCS_PATH . $this->view->docid . '.xml';
     $xsl = APPLICATION_PATH . 'modules/contingent/controllers/xml2html.xsl';
     $doc = new DOMDocument();
     $doc->substituteEntities = TRUE;
     $doc->load($xsl);
     $proc = new XsltProcessor();
     $proc->importStylesheet($doc);
     $doc->load($xml);
     $proc->setParameter('', 'contextPath', '/');
     $proc->setParameter('', 'nodeResPath', '/res/' . $this->view->docid . '/');
     echo $proc->transformToXml($doc);
 }
 private function xsltTransform($xmlStr, $xslFile, $toDom = false)
 {
     $doc = new DOMDocument();
     $doc->substituteEntities = TRUE;
     //		$doc->resolveExternals = TRUE;
     $doc->load($xslFile);
     $proc = new XsltProcessor();
     $proc->importStylesheet($doc);
     $doc->loadXML($xmlStr);
     if ($toDom) {
         return $proc->transformToDoc($doc);
     } else {
         return $proc->transformToXml($doc);
     }
 }
 public function xhtmlAction()
 {
     $this->_helper->viewRenderer->setNoRender();
     $xml = DOCS_PATH . $this->view->docid . '.xml';
     $xsl = APPLICATION_PATH . 'modules/site/controllers/xml2html.xsl';
     $doc = new DOMDocument();
     $doc->substituteEntities = TRUE;
     $doc->load($xsl);
     $proc = new XsltProcessor();
     $proc->importStylesheet($doc);
     @$doc->load($xml);
     $proc->setParameter('', 'contextPath', '/');
     $proc->setParameter('', 'nodeResPath', '/res/' . $this->view->docid . '/');
     $proc->registerPHPFunctions('TypecontentController::widget');
     echo $proc->transformToXml($doc);
 }
Exemplo n.º 9
0
 /**
  * Render the table.
  *
  * @param mixed $tableDom
  * @param mixed $config
  */
 public function render(Document $reportDom, Config $config)
 {
     $template = $config['template'];
     $out = strtr($config['file'], ['%report_name%' => $reportDom->firstChild->getAttribute('name')]);
     if (!file_exists($template)) {
         throw new \RuntimeException(sprintf('XSLT template file "%s" does not exist', $template));
     }
     foreach ($reportDom->query('.//row') as $rowEl) {
         $formatterParams = [];
         foreach ($rowEl->query('./formatter-param') as $paramEl) {
             $formatterParams[$paramEl->getAttribute('name')] = $paramEl->nodeValue;
         }
         foreach ($rowEl->query('./cell') as $cellEl) {
             $value = $cellEl->nodeValue;
             if ('' !== $value && $cellEl->hasAttribute('class')) {
                 $classes = explode(' ', $cellEl->getAttribute('class'));
                 $value = $this->formatter->applyClasses($classes, $value, $formatterParams);
                 $cellEl->nodeValue = $value;
             }
         }
     }
     $stylesheetDom = new \DOMDocument('1.0');
     $stylesheetDom->load($template);
     $xsltProcessor = new \XsltProcessor();
     $xsltProcessor->importStylesheet($stylesheetDom);
     $xsltProcessor->setParameter(null, 'title', $config['title']);
     $xsltProcessor->setParameter(null, 'phpbench-version', PhpBench::VERSION);
     $xsltProcessor->setParameter(null, 'date', date('Y-m-d H:i:s'));
     $output = $xsltProcessor->transformToXml($reportDom);
     if (!$output) {
         throw new \InvalidArgumentException(sprintf('Could not render report with XSL file "%s"', $template));
     }
     if ($out) {
         file_put_contents($out, $output);
         $this->output->writeln('Dumped XSLT report:');
         $this->output->writeln($out);
     } else {
         $this->output->write($output);
     }
 }
Exemplo n.º 10
0
function do_transformation($xml, $xsl, &$result, $option)
{
    if ($option == 'xml') {
        header("Content-type: application/xml");
        $result = $xml;
        return 1;
    } else {
        if ($option == 'xsl') {
            /**
             * Compatibility function wrappers. These are function's wrappers that make
             * available functions found on newer PHP versions (mostly 4.3 ones).
             */
            $version = explode(".", phpversion());
            $major = $version[0];
            $minor = $version[1];
            $release = $version[2];
            if ($major >= 5) {
                $xmlDOM = new DomDocument();
                $xslDOM = new DomDocument();
                $xsltEngine = new XsltProcessor();
                $xmlDOM->loadXML($xml);
                $xslDOM->load($xsl);
                $xsltEngine->importStylesheet($xslDOM);
                $transformation = $xsltEngine->transformToXml($xmlDOM);
                echo $transformation;
                return 1;
            } else {
                $xsl_proc = xslt_create();
                xslt_set_encoding($xsl_proc, "ISO-8859-1");
                $arg = array('/_xml' => $xml);
                $result = xslt_process($xsl_proc, $xml, $xsl, NULL, $arg);
                xslt_free($xsl_proc);
                return 1;
            }
        } else {
            return 0;
        }
    }
}
Exemplo n.º 11
0
            </SERVE>';
    }
    $body .= '</serves>';
    $body = utf8_encode($body);
    if ($_POST["generate"] == "server") {
        # LOAD XML FILE
        $dom_content = new DOMDocument();
        $dom_content->loadXML($body);
        # START XSLT
        $processor = new XsltProcessor();
        $dom_stylesheet = new DomDocument();
        $dom_stylesheet->load($_POST['stylesheet']);
        $processor->importStylesheet($dom_stylesheet);
        # PRINT
        @header("Content-Type: text/html; charset=UTF-8");
        echo $processor->transformToXml($dom_content);
    }
    if ($_POST["generate"] == "client") {
        @header("Content-Type: text/xml; charset=UTF-8");
        echo $body;
    }
    exit;
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Get Serves</title>
        <link href="stylesheet.css" rel="stylesheet" type="text/css" />
Exemplo n.º 12
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>";