function smarty_modifier_xslt($xml, $xslfile = '') { $xh = xslt_create(); $arguments = array('/_xml' => $xml); return xslt_process($xh, 'arg:/_xml', $xslfile, NULL, $arguments); xslt_free($xh); }
function transform() { $xslhandler = xslt_create(); $this->outputXML = xslt_process($xslhandler, $this->{$inputXML}, $this->{$xslTransform}); xslt_free($xslhandler); return $this->outputXML; }
function INCLUDE_xml_xsl($xmlContent, $xslFile) { $p = xslt_create(void); $args = array('/_xml' => $xmlContent); $result = xslt_process($p, 'arg:/_xml', $xslFile, NULL, $args); xslt_free($p); return utf8_decode($result); }
function perform_xslt($xml, $s, $islast, $isfirst, $param_path) { global $base_path, $charset; $transform = "{$base_path}/admin/convert/imports/" . $param_path . "/" . $s['XSLFILE'][0]['value']; //Si c'est la première transformation, on rajoute les entêtes if ($isfirst) { if ($s['ENCODING']) { $xml1 = "<?xml version=\"1.0\" encoding=\"" . $s['ENCODING'] . "\"?>\n<" . $s['ROOTELEMENT'][0]["value"]; } else { $xml1 = "<?xml version=\"1.0\" encoding=\"{$charset}\"?>\n<" . $s['ROOTELEMENT'][0]["value"]; } if ($s["NAMESPACE"]) { $xml1 .= " xmlns:" . $s["NAMESPACE"][0]["ID"] . "='" . $s["NAMESPACE"][0]["value"] . "' "; } $xml1 .= ">\n" . $xml . "\n</" . $s['ROOTELEMENT'][0]['value'] . ">"; $xml = $xml1; } $f = fopen($transform, "r"); $xsl = fread($f, filesize($transform)); fclose($f); //Création du processeur $xh = xslt_create(); //Encodage = $charset if (defined("ICONV_IMPL")) { xslt_set_encoding($xh, "{$charset}"); } // Traite le document if ($result = @xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, array("/_xml" => $xml, "/_xsl" => $xsl))) { $r['VALID'] = true; $r['DATA'] = $result; $r['ERROR'] = ""; //Si c'est la dernière transformation, on supprime les entêtes et l'élément root if ($islast) { $p = preg_match("/<" . $s['TNOTICEELEMENT'][0]['value'] . "(?:\\ [^>]*|)>/", $r["DATA"], $m, PREG_OFFSET_CAPTURE); if ($p) { $r['DATA'] = " " . substr($r['DATA'], $m[0][1]); } $p1 = 0; $p = 0; while ($p !== false) { $p1 = $p; $p = @strpos($r['DATA'], "</" . $s['TNOTICEELEMENT'][0]['value'] . ">", $p1 + strlen("</" . $s['TNOTICEELEMENT'][0]['value'] . ">")); } if ($p1 !== false && $p1 != 0) { $r['DATA'] = substr($r['DATA'], 0, $p1 + strlen($s['TNOTICEELEMENT'][0]['value']) + 3) . "\n"; } } } else { $r['VALID'] = false; $r['DATA'] = ""; $r['ERROR'] = "Sorry, notice could not be transformed by {$transform} the reason is that " . xslt_error($xh) . " and the error code is " . xslt_errno($xh); } xslt_free($xh); return $r; }
function apply_transform($title, $content) { if (!$this->xslt_extension_availible) { return 'The xslt_transformation used, needs the "xslt" extension of php !!!'; } $xh = xslt_create(); $xsltarguments = array('/_xml' => $content); $result = xslt_process($xh, 'arg:/_xml', $this->xsltfile, NULL, $xsltarguments, $this->xsltparameters); xslt_free($xh); return $result; }
function xml_select($xpath, $file) { $xsl = "<?xml version='1.0'?>\n" . "<xsl:transform version='1.0' " . "xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>\n" . "<xsl:template match='/'>\n" . "<resultset>\n" . "<xsl:apply-templates select='{$xpath}'/>\n" . "</resultset>\n" . "</xsl:template>\n" . "<xsl:template match='node()|@*'>\n" . "<xsl:copy>\n" . "<xsl:apply-templates select='node()|@*'/>\n" . "</xsl:copy>\n" . "</xsl:template>\n" . "</xsl:transform>\n"; $e = xslt_create(); $o = xslt_process($e, $file, 'arg:/xsl', NULL, array('xsl' => $xsl), array('path' => $xpath)); if (!$o) { print_lined($xsl); } xslt_free($e); return $o; }
function transform() { global $ilLog; $this->__init(); $this->fo_string = @xslt_process($this->xslt_handler, "arg:/_xml", "arg:/_xsl", null, $this->xslt_args, $this->xslt_params); if (strlen($error_msg = xslt_error($this->xslt_handler))) { $ilLog->write("Error generating pdf: " . $error_msg); return false; } xslt_free($this->xslt_handler); return true; }
function INCLUDE_xml_xsl($xmlContent, $xslFile) { $fp = fopen($xslFile, "r"); if ($fp) { $xsl = fread($fp, "500000"); fclose($fp); } $p = xslt_create(void); $args = array("/_stylesheet", $xsl, "/_xmlinput", $xmlContent, "/_output", 0, 0); $runFlag = xslt_run($p, "arg:/_stylesheet", "arg:/_xmlinput", "arg:/_output", 0, $args); $result = xslt_fetch_result($p, "arg:/_output"); xslt_free($p); return utf8_decode($result); }
function output($output) { /* Falls die Seite als HTML ausgegeben werden soll */ /* Eine Weiche einbauen, fals die XSLT Extension nicht geladen ist -> http://koders.com/php/fidB0434D36F01703F9ACAB5E21065E315FE44D2C57.aspx?s=xslt_process http://koders.com/php/fid78371B5F37DAE258E3258B91CC791A712CBF2AAC.aspx?s=xslt_process */ if (isset($_SESSION['variables']['extention']) and $_SESSION['variables']['extention'] == "html" and IS_XSLT) { if (version_compare(phpversion(), "5.0", ">")) { $processor = new XSLTProcessor(); $xmlDom = new DOMDocument(); $xslDom = new DOMDocument(); $xmlDom->loadXML($output); $xslDom->load(BIN_DIR . "xslt/index.xsl"); $processor->importstylesheet($xslDom); /* Transformiert den Output :TODO: Fehlerabfrage der Resultates :ATTENTION: eventuell werden die im XSL-File includeten Dateien falsch eingebunden*/ $result = $processor->transformtoxml($xmlDom); } else { /* PHP4 XSLT Prozessor, ist auch unter PHP5 erreichbar, nur langsamer */ /* XSL File auslesen und Content ueberschreiben */ $filename = "xslt/main.xsl"; $handle = fopen($filename, "r"); $xsl_contents = fread($handle, filesize($filename)); fclose($handle); /* :TODO: Anpassen des xsc fuer die Uebergabe des Templatefiles */ // $xsl = sprintf($xsl_contents, $_SESSION['variables']['template_content']); $xsl = $xsl_contents; /* Stylesheet uebergeben */ $processor_arguments = array('/_xml' => $output, '/_xsl' => $xsl); $processor = xslt_create(); xslt_set_encoding($processor, 'ISO-8859-1'); xslt_set_base($processor, 'file://' . BIN_DIR . 'xslt/'); /* Transformiert den Output */ $result = xslt_process($processor, 'arg:/_xml', 'arg:/_xsl', NULL, $processor_arguments); if (!$result && xslt_errno($processor) > 0) { $result = sprintf("Kann XSLT Dokument nicht umarbeiten [%d]: %s", xslt_errno($processor), xslt_error($processor)); } xslt_free($processor); } /* Gibt das HTML-Dokument aus */ echo $result; } else { header("Content-Type: text/xml"); echo $output; } }
/** * Transformation générique d'un document XML via XSLT * @param string $filename nom du fichier source * @param string $filename_source nom du fichier en sortie * @param string $stylesheet nom de la feuille XSLT * @param array $params paramètres à passer à la feuille XSLT * @access private * @return boolean vrai quand tout se passe bien */ function _output_xsl_generic_transform($filename, $filename_cible, $stylesheet, $params = array()) { /* Attention : code hautement toxique, il a fallu aller fouiller dans les sources de PHP pour découvrir une grande partie des engins nucléaires en jeu ici et rien ne garantit leur stabilité. Désolé pour le développement durable, c'est pas trop ça ici. */ $xh = xslt_create(); $result = xslt_process($xh, $filename, PATH_INCLUDE . "xslt/" . $stylesheet, $filename_cible, array(), $params); if (!$result) { $msgerr = 'Erreur XSLT ' . xslt_errno($xh) . ' : ' . xslt_error($xh); xslt_free($xh); return false; } else { return true; } }
function xsltTransform($xmlString, $xsltPath, $xsltArguments = null) { if (!file_exists($xsltPath)) { webserviceError('&error-xslt-path-not-found;', 500, array('path' => $xsltPath)); } $result = null; $xsltEnabledStatus = getXsltEnabledStatus(); switch ($xsltEnabledStatus) { case 'php5': $xslt = new XSLTProcessor(); $xsltDocument = new DOMDocument(); $xsltDocument->load($xsltPath); $xslt->importStyleSheet($xsltDocument); if (is_array($xsltArguments)) { foreach ($xsltArguments as $key => $value) { $xslt->setParameter('', $key, $value); } } $errorLevelToDescribeMerelyDeprecatedWarnings = 999999; $xmlDocument = new DOMDocument(); $xmlDocument->loadXML($xmlString); $result = $xslt->transformToXML($xmlDocument); break; case 'php4': $xsltproc = xslt_create(); $xmlString = array('/_xml' => $xmlString); $xsltPath = 'file://' . $xsltPath; $result = @xslt_process($xsltproc, 'arg:/_xml', $xsltPath, NULL, $xmlString, $xsltArguments) or webServiceError('&error-xslt-processor-error;', 500, array('path' => $xsltPath, 'errorMessage' => xslt_error($xsltproc))); if (empty($result) or xslt_error($xsltproc) != null) { webServiceError('&error-xslt-processor-error;', 500, array('path' => $xsltPath, 'errorMessage' => xslt_error($xsltproc))); } xslt_free($xsltproc); break; default: $commandLineMessage = ''; $phpVersion = getPhpVersion(); if ($phpVersion >= 5) { webServiceError('&error-xslt-not-available;'); } else { webServiceError('&error-php5-required;', 500, array('phpVersion' => $phpVersion)); } } return $result; }
function odt2spip_traiter_mathml($chemin_fichier) { // recuperer le contenu du fichier if (!$mathml = file_get_contents($chemin_fichier)) return(_T('odtspip:err_transformation_xslt_mathml')); // virer le DOCTYPE qui plante le parseur vu que la dtd n'est pas disponible $mathml = preg_replace('/<!DOCTYPE.*?>/i', '', $mathml); // variable en dur pour xslt utilisée // $xml_entre = _DIR_TMP.'odt2spip/'.$id_auteur.'/content.xml'; // chemin du fichier xml à lire $xslt_texte = _DIR_PLUGIN_ODT2SPIP.'inc/xsltml/mmltex.xsl'; // chemin de la xslt à utiliser pour les maths // appliquer la transformation XSLT sur le fichier content.xml // déterminer les fonctions xslt à utiliser (php 4 ou php 5) if (!class_exists('XSLTProcessor')) { // on est en php4 : utiliser l'extension et les fonction xslt de Sablotron // Crée le processeur XSLT $xh = xslt_create(); // si on est sur un serveur Windows utiliser xslt_set_base avec le préfixe file:// if (strpos($_SERVER['SERVER_SOFTWARE'], 'Win') !== false) xslt_set_base($xh, 'file://' . getcwd () . '/'); // lancer le parseur $arguments = array('/_xml' => $mathml); $latex_sortie = xslt_process($xh, 'arg:/_xml', $xslt_texte, NULL, $arguments); if (!$latex_sortie) return(_T('odtspip:err_transformation_xslt_mathml')); // Détruit le processeur XSLT xslt_free($xh); } else { // on est php5: utiliser les fonctions de la classe XSLTProcessor $proc = new XSLTProcessor(); $xml = new DOMDocument(); $xml->loadXML($mathml); $xsl = new DOMDocument(); $xsl->load($xslt_texte); $proc->importStylesheet($xsl); // attachement des règles xsl // lancer le parseur if (!$latex_sortie = $proc->transformToXml($xml)) return(_T('odtspip:err_transformation_xslt_mathml')); } return $latex_sortie; }
function doTransform($xmlfilename, $xslfilename) { $xh = xslt_create(); if (!$xh) { echo "<p>ERROR: unable to invoke php's xslt processor"; return; } $root = 'file://' . $_SERVER['DOCUMENT_ROOT']; $result = xslt_process($xh, $root . $xmlfilename, $root . $xslfilename); if ($result) { header("Content-type: application/ms-excel"); //header("Content-type: application/vnd.ms-excel"); header('Content-Disposition: attachment; filename="' . $GLOBALS['outfile'] . '.xls";'); echo $result; } else { echo "<p>ERROR: unable to transform " . $xmlfilename; echo "<br>" . xslt_error($xh); } xslt_free($xh); }
function processor_xslt($formatter, $value) { global $DBInfo; if ($value[0] == '#' and $value[1] == '!') { list($line, $value) = explode("\n", $value, 2); # get parameters $args = explode(" ", substr($lines[0], 6), 2); } $xsltproc = xslt_create(); # xslt_set_encoding ($xsltproc, "UTF-8"); $xsl = NULL; list($line, $body) = explode("\n", $value, 2); $buff = ""; while ($line[0] == '<' and $line[1] == '?') { preg_match("/^<\\?xml-stylesheet\\s+href=\"([^\"]+)\"/", $line, $match); if ($match) { if ($DBInfo->hasPage($match[1])) { $xsl = getcwd() . '/' . $DBInfo->text_dir . '/' . $match[1]; $line = '<?xml-stylesheet href="' . $xsl . '" type="text/xml"?>'; } $flag = 1; } $buff .= $line . "\n"; list($line, $body) = explode("\n", $body, 2); if ($flag) { break; } } $src = $buff . $line . "\n" . $body; $arguments = array('/_xml' => $src); $html = xslt_process($xsltproc, 'arg:/_xml', $xsl, NULL, $arguments); # $html = xslt_process($xsltproc,'arg:/_xml',NULL,NULL,$arguments); if (!$html) { return "<pre class='code'>\n{$balue}\n</pre>\n"; } xslt_free($xsltproc); if (function_exists("iconv")) { $html = iconv('UTF-8', $DBInfo->charset, $html); } return $html; }
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; } } }
function run() { if (is_null($this->_sXML)) { print "ERROR: no XML file specified"; return; } if (is_null($this->_sXSLT)) { print "ERROR: no XSLT file specified"; return; } $oXSLT = xslt_create(); $sRst = xslt_process($oXSLT, $this->_sXML, $this->_sXSLT, $this->_sOutput, null, $this->_aParms); xslt_free($oXSLT); return $sRst; }
function getFO() { $xml = $this->getXMLFromDom(false, true, true); $xsl = file_get_contents("./Services/COPage/xsl/page_fo.xsl"); $args = array('/_xml' => $xml, '/_xsl' => $xsl); $xh = xslt_create(); $params = array(); $fo = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params); var_dump($fo); // do some replacements $fo = str_replace("\n", "", $fo); $fo = str_replace("<br/>", "<br>", $fo); $fo = str_replace("<br>", "\n", $fo); xslt_free($xh); // $fo = substr($fo, strpos($fo, ">") + 1); //echo "<br><b>fo:</b><br>".htmlentities($fo); flush(); return $fo; }
/** * Convert a print output to XSL-FO * * @param string $print_output The print output * @return string XSL-FO code * @access public */ function processPrintoutput2FO($print_output) { if (extension_loaded("tidy")) { $config = array("indent" => false, "output-xml" => true, "numeric-entities" => true); $tidy = new tidy(); $tidy->parseString($print_output, $config, 'utf8'); $tidy->cleanRepair(); $print_output = tidy_get_output($tidy); $print_output = preg_replace("/^.*?(<html)/", "\\1", $print_output); } else { $print_output = str_replace(" ", " ", $print_output); $print_output = str_replace("⊗", "X", $print_output); } $xsl = file_get_contents("./Modules/Test/xml/question2fo.xsl"); // additional font support $xsl = str_replace('font-family="Helvetica, unifont"', 'font-family="' . $GLOBALS['ilSetting']->get('rpc_pdf_font', 'Helvetica, unifont') . '"', $xsl); $args = array('/_xml' => $print_output, '/_xsl' => $xsl); $xh = xslt_create(); $params = array(); $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params); xslt_error($xh); xslt_free($xh); return $output; }
function _generateReport($xmlFile, $php, $env) { if (version_compare(PHP_VERSION, '5', '>=') && extension_loaded('xsl')) { $this->debug('Including php5 xslt wrapper'); require_once AK_BASE_DIR . DS . 'vendor' . DS . 'xslt-php4-php5' . DS . 'xslt-php4-php5.php'; } // Fail if XSLT extension is not available if (!function_exists('xslt_create')) { $this->error('Cannot generate report: xslt extension missing'); return FALSE; } $currentDir = getcwd(); chdir(AK_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'xsl'); $xsl_file = AK_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'xsl' . DIRECTORY_SEPARATOR . 'phpunit2-noframes.xsl'; // look for xsl if (!is_readable($xsl_file)) { $this->error('Cannot generate report: ' . $xsl_file . ' missing'); chdir($currentDir); return FALSE; } if (!is_readable($xmlFile)) { return false; } $schema = file_get_contents($xmlFile); $xml = new SimpleXMLElement($schema); $suites = $xml->xpath("/testsuites/testsuite"); $tests = 0; $failures = 0; $errors = 0; $time = 0; foreach ($suites as $suite) { $attributes = $suite->attributes(); $tests += (int) $attributes->tests; $failures += (int) $attributes->failures; $errors += (int) $attributes->errors; $time += (double) $attributes->time; } $environment = array(); $environment['php'] = $php; $environment['class'] = $failures > 0 ? 'failure' : $errors > 0 ? 'error' : ''; $environment['backend'] = $env; $environment['tests'] = $tests; $environment['failures'] = $failures; $environment['errors'] = $errors; $environment['time'] = round($time, 3); $link = AK_BASE_DIR . DS . 'test' . DS . 'report' . DS . $php . DS . $env . DS . 'index.html'; $environment['details'] = 'file://' . $link; $this->report_environments[] = $environment; $arguments = array('/_xml' => $schema, '/_xsl' => file_get_contents($xsl_file)); // create an XSLT processor $xh = xslt_create(); // set error handler xslt_set_error_handler($xh, array(&$this, 'xslt_error_handler')); // process the schema $result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); xslt_free($xh); $targetFile = AK_BASE_DIR . DS . 'test' . DS . 'report' . DS . $php . DS . $env . DS . 'index.html'; if (!file_exists(dirname($targetFile))) { mkdir(dirname($targetFile), 0777, true); } file_put_contents($targetFile, $result); chdir($currentDir); }
function destroy() { xslt_free($this->processor); }
function apply_xsl_to_xml($xml, $xsl) { global $charset; $xh = xslt_create(); xslt_set_encoding($xh, $charset); $arguments = array('/_xml' => $xml, '/_xsl' => $xsl); $result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); xslt_free($xh); return $result; }
$fd = fopen('xml/note/' . $file . '.xml', 'r'); while (!feof($fd)) { $line1 = fgets($fd); if ($cpt == 0) { if (match_tag('titre', $line1)) { fputs($fdc, "<titre>" . extract_text('titre', $line1) . " [Compilation]</titre>\n"); } else { if (!match_tag('note', $line1) and !match_tag('meta_note', $line1) and !match_tag('statut', $line1) and !match_tag('date_creation', $line1) and !match_tag('date_modification', $line1) and !match_tag('auteur', $line1) and !match_tag('contributeurs', $line1) and !match_tag('contributeur', $line1) and !match_tag('relecteur', $line1) and !match_tag('nom', $line1) and !match_tag('prenom', $line1) and !isComment($line1)) { fputs($fdc, $line1); } } } else { if (!match_tag('note', $line1) and !match_tag('meta_note', $line1) and !match_tag('statut', $line1) and !match_tag('date_creation', $line1) and !match_tag('date_modification', $line1) and !match_tag('auteur', $line1) and !match_tag('contributeurs', $line1) and !match_tag('contributeur', $line1) and !match_tag('relecteur', $line1) and !match_tag('nom', $line1) and !match_tag('prenom', $line1) and !match_tag('titre', $line1) and !isComment($line1)) { fputs($fdc, $line1); } } } $cpt++; } fputs($fdc, '</note>'); $xh = xslt_create(); if (xslt_process($xh, "xml/note/{$titre}.xml", "xsl/note/note.xsl", "gen/note/{$titre}.xml")) { include 'template1.php'; readfile("gen/note/{$titre}.xml"); include 'template2.php'; } else { echo "Error : " . xslt_error($xh) . " and the "; echo "error code is " . xslt_errno($xh); } xslt_free($xh); }
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>"; }
/** * show media object */ function media($a_mode = "media") { $this->tpl =& new ilTemplate("tpl.fullscreen.html", true, true, "Services/COPage"); include_once "./Services/Style/classes/class.ilObjStyleSheet.php"; $this->tpl->setVariable("LOCATION_STYLESHEET", ilUtil::getStyleSheetLocation()); $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath($this->glossary->getStyleSheetId())); //$int_links = $page_object->getInternalLinks(); $med_links = ilMediaItem::_getMapAreasIntLinks($_GET["mob_id"]); // later //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets()); $link_xlm = ""; require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; $media_obj =& new ilObjMediaObject($_GET["mob_id"]); $xml = "<dummy>"; // todo: we get always the first alias now (problem if mob is used multiple // times in page) $xml .= $media_obj->getXML(IL_MODE_ALIAS); $xml .= $media_obj->getXML(IL_MODE_OUTPUT); $xml .= $link_xml; $xml .= "</dummy>"; $xsl = file_get_contents("./Services/COPage/xsl/page.xsl"); $args = array('/_xml' => $xml, '/_xsl' => $xsl); $xh = xslt_create(); if (!$this->offlineMode()) { $enlarge_path = ilUtil::getImagePath("enlarge.png", false, "output"); $wb_path = ilUtil::getWebspaceDir("output") . "/"; } else { $enlarge_path = "images/enlarge.png"; $wb_path = ""; } $mode = $a_mode; $this->ctrl->setParameter($this, "obj_type", "MediaObject"); $fullscreen_link = $this->getLink($_GET["ref_id"], "fullscreen"); $this->ctrl->clearParameters($this); $params = array('mode' => $mode, 'enlarge_path' => $enlarge_path, 'link_params' => "ref_id=" . $_GET["ref_id"], 'fullscreen_link' => $fullscreen_link, 'ref_id' => $_GET["ref_id"], 'pg_frame' => $pg_frame, 'webspace_path' => $wb_path); $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params); echo xslt_error($xh); xslt_free($xh); // unmask user html $this->tpl->setVariable("MEDIA_CONTENT", $output); $this->tpl->parseCurrentBlock(); if ($this->offlineMode()) { $html = $this->tpl->get(); return $html; } }
static function transformPHP4(&$InformationArray) { // create the XSLT processor^M $xh = xslt_create() or die("Could not create XSLT processor"); // Process the document $result = xslt_process($xh, $InformationArray['fileBase'] . $InformationArray['xml_file'], $InformationArray['fileBase'] . $InformationArray['xslt_file'], $InformationArray['fileBase'] . $InformationArray['out_file']); if (!$result) { // Something croaked. Show the error $InformationArray['error'] = "Cannot process XSLT document: " . xslt_errno($xh) . " " . xslt_error($xh); } // Destroy the XSLT processor xslt_free($xh); }
function RegionInfo($url, $xslFile, $param, $showRegion) { $remoteXMLFile = fopen($url, "r"); if (!$remoteXMLFile) { echo "<p>Unable to open remote file.\n"; exit; } $xmlData = ""; while (!feof($remoteXMLFile)) { $xmlData .= fgets($remoteXMLFile, 1024); } fclose($remoteXMLFile); $html = ""; if (PHP_VERSION >= 5) { $arguments = array('/_xml' => $xmlData, '/_xsl' => file_get_contents($xslFile)); $xsltproc = xsltCreate(); $html = xsltProcess($xsltproc, 'arg:/_xml', 'arg:/_xsl', null, $arguments); xsltFree($xsltproc); } else { $xsltHandle = xslt_create() or die("Can't create XSLT handle!"); // Open the XML and XSL files $xslStyleSheet = fopen($xslFile, "r") or die("Can't open XSL file"); // Read in the XML and XSL contents $xslContent = fread($xslStyleSheet, filesize($xslFile)); $arg = array('/_xml' => $xmlData, '/_xsl' => $xslContent); $param = array('regionName' => $param, 'showRegion' => $showRegion); // Perform the XSL transformation $html = @xslt_process($xsltHandle, 'arg:/_xml', 'arg:/_xsl', NULL, $arg, $param); // Free up the resources @xslt_free($xsltHandle); } return $html; }
function exportMediaFullscreen($a_target_dir, $pg_obj) { $subdir = "il_" . IL_INST_ID . "_mob_" . $this->getId(); $a_target_dir = $a_target_dir . "/objects/" . $subdir; ilUtil::makeDir($a_target_dir); $tpl = new ilTemplate("tpl.fullscreen.html", true, true, "Modules/LearningModule"); $tpl->setCurrentBlock("ilMedia"); //$int_links = $page_object->getInternalLinks(); $med_links = ilMediaItem::_getMapAreasIntLinks($this->getId()); // @todo //$link_xml = $this->getLinkXML($med_links, $this->getLayoutLinkTargets()); require_once "./Services/MediaObjects/classes/class.ilObjMediaObject.php"; //$media_obj = new ilObjMediaObject($_GET["mob_id"]); require_once "./Services/COPage/classes/class.ilPageObject.php"; $xml = "<dummy>"; // todo: we get always the first alias now (problem if mob is used multiple // times in page) $xml .= $pg_obj->getMediaAliasElement($this->getId()); $xml .= $this->getXML(IL_MODE_OUTPUT); //$xml.= $link_xml; $xml .= "</dummy>"; //die(htmlspecialchars($xml)); $xsl = file_get_contents("./Services/COPage/xsl/page.xsl"); $args = array('/_xml' => $xml, '/_xsl' => $xsl); $xh = xslt_create(); //echo "<b>XML:</b>".htmlentities($xml); // determine target frames for internal links $wb_path = ""; $enlarge_path = ""; $params = array('mode' => "fullscreen", 'enlarge_path' => $enlarge_path, 'link_params' => "ref_id=" . $_GET["ref_id"], 'fullscreen_link' => "", 'ref_id' => $_GET["ref_id"], 'webspace_path' => $wb_path); $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params); //echo xslt_error($xh); xslt_free($xh); // unmask user html include_once "./Services/MediaObjects/classes/class.ilPlayerUtil.php"; $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", "../../css/style.css"); $tpl->setVariable("LOCATION_STYLESHEET", "../../css/system.css"); $tpl->setVariable("MEDIA_CONTENT", $output); $output = $tpl->get(); //$output = preg_replace("/\/mobs\/mm_(\d+)\/([^\"]+)/i","$2",$output); $output = preg_replace("/mobs\\/mm_(\\d+)\\/([^\"]+)/i", "\$2", $output); $output = preg_replace("/\\.\\/Services\\/MediaObjects\\/flash_mp3_player/i", "../../players", $output); $output = preg_replace("/\\.\\/" . str_replace("/", "\\/", ilPlayerUtil::getFlashVideoPlayerDirectory()) . "/i", "../../players", $output); $output = preg_replace("/file=..\\/..\\/..\\//i", "file=../objects/" . $subdir . "/", $output); //die(htmlspecialchars($output)); fwrite(fopen($a_target_dir . '/fullscreen.html', 'w'), $output); }
function TransformSchema($schema, $xsl, $schematype = 'string') { // Fail if XSLT extension is not available if (!function_exists('xslt_create')) { return FALSE; } $xsl_file = dirname(__FILE__) . '/xsl/' . $xsl . '.xsl'; // look for xsl if (!is_readable($xsl_file)) { return FALSE; } switch ($schematype) { case 'file': if (!is_readable($schema)) { return FALSE; } $schema = _file_get_contents($schema); break; case 'string': default: if (!is_string($schema)) { return FALSE; } } $arguments = array('/_xml' => $schema, '/_xsl' => _file_get_contents($xsl_file)); // create an XSLT processor $xh = xslt_create(); // set error handler xslt_set_error_handler($xh, array(&$this, 'xslt_error_handler')); // process the schema $result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments); xslt_free($xh); return $result; }
/** * Atom 0.3 を RSS 1.0 に変換する(PHP4, XSLT) */ function atom_to_rss_by_xslt($input, $stylesheet, $output) { $xh = xslt_create(); if (!@xslt_process($xh, $input, $stylesheet, $output)) { $errmsg = xslt_errno($xh) . ': ' . xslt_error($xh); P2Util::pushInfoHtml('<p>p2 error: XSLT - AtomをRSSに変換できませんでした。(' . $errmsg . ')</p>'); xslt_free($xh); return FALSE; } xslt_free($xh); return FileCtl::file_read_contents($output); }
/** Do the XSLT translation and look in the local directory if the file * doesn't exist */ function generate_XSLT($xml, $pageName, $only_in_local = false) { // For common xsl pages not referenced directly // i.e. header, headerback, etc... // look if they are in the local directory, and set // an XML value accordingly include "cdash/config.php"; if ($CDASH_USE_LOCAL_DIRECTORY && !$only_in_local) { $pos = strpos($xml, "</cdash>"); // this should be the last if ($pos !== FALSE) { $xml = substr($xml, 0, $pos); $xml .= "<uselocaldirectory>1</uselocaldirectory>"; // look at the local directory if we have the same php file // and add the xml if needed $localphpfile = "local/" . $pageName . ".php"; if (file_exists($localphpfile)) { include_once $localphpfile; $xml .= getLocalXML(); } $xml .= "</cdash>"; // finish the xml } } $xh = xslt_create(); if (PHP_VERSION < 5) { $filebase = 'file://' . getcwd() . '/'; xslt_set_base($xh, $filebase); } $arguments = array('/_xml' => $xml); if (!empty($CDASH_DEBUG_XML)) { $tmp = eregi_replace("(\\<)([A-Za-z0-9\\-_.]{1,250})(\\>)", "\\0\n", $xml); $tmp = eregi_replace("(\\</)([A-Za-z0-9\\-_.]{1,250})(\\>)", "\n\\0\n", $tmp); $inF = fopen($CDASH_DEBUG_XML, "w"); fwrite($inF, $tmp); fclose($inF); unset($inF); } $xslpage = $pageName . ".xsl"; // Check if the page exists in the local directory if ($CDASH_USE_LOCAL_DIRECTORY && file_exists("local/" . $xslpage)) { $xslpage = "local/" . $xslpage; } $html = xslt_process($xh, 'arg:/_xml', $xslpage, NULL, $arguments); // Enfore the charset to be UTF-8 header('Content-type: text/html; charset=utf-8'); echo $html; xslt_free($xh); }