function setXslBaseUri($uri) { if ($uri != "") { xslt_set_base($this->processor, $uri); } return true; }
function setXslBaseUri($uri) { if ($uri != "") { if (strpos(' ' . $uri, 'file://') == 0) { $uri = 'file://' . $uri; } // eh obrigatorio file:// para Windows xslt_set_base($this->processor, $uri); } return true; }
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; } }
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; }
/** 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); }
$transform = "simpletest.org.xslt"; $source_paths = array("../../docs/wiki/", "en" => "../../docs/source/en/", "fr" => "../../docs/source/fr/"); $destination_path = "../../../../simpletest.org/wiki/data/"; foreach ($source_paths as $lang => $source_path) { if (!is_int($lang)) { $prefix = $lang . '-'; } $dir = opendir($source_path); while (($file = readdir($dir)) !== false) { if (!preg_match('/\\.xml$/', $file)) { continue; } $source = $source_path . $file; $destination = $destination_path . $prefix . preg_replace('/\\.xml$/', '.txt', basename($source)); $xsltProcessor = xslt_create(); $fileBase = 'file://' . getcwd() . '/'; xslt_set_base($xsltProcessor, $fileBase); $result = xslt_process($xsltProcessor, $source, $transform); $result = preg_replace("/((<a href=\")([a-z_]*)(\\.php\">))/", "<a href=\"doku.php?id=fr-\\3\">", $result); if ($result) { $handle = fopen($destination, "w+"); fwrite($handle, $result); fclose($handle); echo "succès pour " . $destination . "<br />"; } else { echo "erreur pour " . $destination . " : " . xslt_error($xh) . "<br />"; } xslt_free($xsltProcessor); } closedir($dir); }