Ejemplo n.º 1
1
 /**
  * Transforms the given XML data and XSL stylesheet and
  * returns the completed transformation as a string, or returns
  * zero (0) in case of failure.  Note: The $params property only
  * works with more recent versions of PHP (ie. 4.2+).
  * 
  * @access	public
  * @param	string	$xsl_data
  * @param	string	$xml_data
  * @param	associative array	$params
  * @return	string
  * 
  */
 function process($xsl_data = '', $xml_data = '', $params = array())
 {
     if (PHP_VERSION < '4.1.0') {
         if (xslt_process($xsl_data, $xml_data, $res)) {
             return $res;
         } else {
             return 0;
         }
     } else {
         $args = array();
         if (@file_exists($xsl_data)) {
             $xsltfile = $xsl_data;
         } else {
             $xsltfile = 'arg:/_xsl';
             $args['/_xsl'] = $xsl_data;
         }
         if (@file_exists($xml_data)) {
             $xmlfile = $xml_data;
         } else {
             $xmlfile = 'arg:/_xml';
             $args['/_xml'] = $xml_data;
         }
         $res = xslt_process($this->handle, $xmlfile, $xsltfile, null, $args, $params);
         if ($res) {
             return $res;
         } else {
             return 0;
         }
     }
 }
Ejemplo n.º 2
0
 function transform()
 {
     $xslhandler = xslt_create();
     $this->outputXML = xslt_process($xslhandler, $this->{$inputXML}, $this->{$xslTransform});
     xslt_free($xslhandler);
     return $this->outputXML;
 }
Ejemplo n.º 3
0
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);
}
Ejemplo n.º 4
0
function upload_article_handler(&$request, &$session, &$files) {
	$publication = Input::Get('Pub', 'int', 0);
	$issue = Input::Get('Issue', 'int', 0);
	$section = Input::Get('Section', 'int', 0);
	$language = Input::Get('Language', 'int', 0);
	$sLanguage = Input::Get('sLanguage', 'int', 0);
	$articleNumber = Input::Get('Article', 'int', 0);

	if (!Input::IsValid()) {
		echo "Input Error: Missing input";
		return;
	}

	// Unzip the sxw file to get the content.
	$zip = zip_open($files["filename"]["tmp_name"]);
	if ($zip) {
		$xml = null;
		while ($zip_entry = zip_read($zip)) {
			if (zip_entry_name($zip_entry) == "content.xml") {
		       	if (zip_entry_open($zip, $zip_entry, "r")) {
		           	$xml = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
			        zip_entry_close($zip_entry);
		       	}
			}
		}
		zip_close($zip);

		if (!is_null($xml)) {
			// Write the XML to a file because the XSLT functions
			// require it to be in a file in order to be processed.
			$tmpXmlFilename = tempnam("/tmp", "ArticleImportXml");
			$tmpXmlFile = fopen($tmpXmlFilename, "w");
			fwrite($tmpXmlFile, $xml);
			fclose($tmpXmlFile);

			// Transform the OpenOffice document to DocBook format.
			$xsltProcessor = xslt_create();
			$docbookXml = xslt_process($xsltProcessor,
									   $tmpXmlFilename,
									   "sxwToDocbook.xsl");
			unlink($tmpXmlFilename);

			// Parse the docbook to get the data.
			$docBookParser = new DocBookParser();
			$docBookParser->parseString($docbookXml, true);

			$article = new Article($articleNumber, $language);
			$article->setTitle($docBookParser->getTitle());
			$article->setIntro($docBookParser->getIntro());
			$article->setBody($docBookParser->getBody());

			// Go back to the "Edit Article" page.
			header("Location: /$ADMIN/articles/edit.php?Pub=$publication&Issue=$issue&Section=$section&Article=$articleNumber&Language=$language&sLanguage=$sLanguage");
		} // if (!is_null($xml))
	} // if ($zip)

	// Some sort of error occurred - show the upload page again.
	include("index.php");
} // fn upload_article_handler
Ejemplo n.º 5
0
 function process($xsl_data = '', $xml_data = '')
 {
     if (@xslt_process($xsl_data, $xml_data, $res)) {
         return $res;
     } else {
         return 0;
     }
 }
Ejemplo n.º 6
0
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 front_xhtml_output()
{
    $buf = ob_get_contents();
    $xh = xslt_create();
    $args = array('/_xml' => '<' . '?xml version="1.0" encoding="utf-8"?' . '>' . $buf);
    ob_end_clean();
    $params = array('path_site_root' => PATH_SITE_ROOT);
    $result = xslt_process($xh, 'arg:/_xml', PATH_INC_FRONTEND . 'front_xhtml.xsl', null, $args, $params);
    eval('?>' . $result);
}
Ejemplo n.º 8
0
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;
 }
Ejemplo n.º 10
0
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;
}
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
 function transform()
 {
     $args = array('/_xml' => $this->xml, '/_xsl' => $this->xsl);
     $result = xslt_process($this->processor, 'arg:/_xml', 'arg:/_xsl', NULL, $args);
     if ($result) {
         $this->setOutput($result);
     } else {
         //            $err = "Error: " . xslt_error ($this->processor) . " Errorcode: " . xslt_errno ($this->processor);
         $this->setError(xslt_error($this->processor));
         $this->setErrorCode(xslt_errno($this->processor));
     }
 }
Ejemplo n.º 13
0
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 process()
 {
     if (parent::isError($process = parent::process())) {
         return $process;
     }
     // Prepare the params for passing to the stylesheet
     $params = array('filter' => $this->filter, 'browser' => $this->browser, 'comment' => $this->comment);
     $xh = xslt_create();
     $result = xslt_process($xh, $this->CSSMLDoc, $this->stylesheetDoc, null, $this->arguments, $params);
     if ($this->output != 'STDOUT') {
         $fp = fopen($this->output, 'w');
         fwrite($fp, $result);
         fclose($fp);
         $result = true;
     }
     return $result;
 }
Ejemplo n.º 16
0
function blackboard_convert($dir)
{
    global $CFG, $OUTPUT;
    throw new coding_exception('bb_convert was not converted to new file api yet, sorry');
    // Check for a Blackboard manifest file
    if (is_readable($dir . '/imsmanifest.xml') && !is_readable($dir . '/moodle.xml')) {
        if (!function_exists('xslt_create')) {
            // XSLT MUST be installed for this to work
            echo $OUTPUT->notification('You need the XSLT library installed in PHP to open this Blackboard file');
            return false;
        }
        //Select the proper XSL file
        $xslt_file = choose_bb_xsl($dir . '/imsmanifest.xml');
        //TODO: Use the get_string function for this
        echo "<li>Converting Blackboard export</li>";
        // The XSL file must be in the same directory as the Blackboard files when it is processed
        if (!copy($CFG->dirroot . "/backup/bb/{$xslt_file}", "{$dir}/{$xslt_file}")) {
            echo $OUTPUT->notification('Could not copy the XSLT file to ' . "{$dir}/{$xslt_file}");
            return false;
        }
        // Change to that directory
        $startdir = getcwd();
        chdir($dir);
        // Process the Blackboard XML files with the chosen XSL file.
        // The imsmanifest contains all the XML files and their relationships.
        // The XSL processor will open them as needed.
        $xsltproc = xslt_create();
        if (!xslt_process($xsltproc, 'imsmanifest.xml', "{$dir}/{$xslt_file}", "{$dir}/moodle.xml")) {
            echo $OUTPUT->notification('Failed writing xml file');
            chdir($startdir);
            return false;
        }
        // Copy the Blackboard course files into the moodle course_files structure
        $subdirs = get_subdirs($dir . "/");
        mkdir("{$dir}/course_files", $CFG->directorypermissions);
        foreach ($subdirs as $subdir) {
            rename($subdir, "course_files/{$subdir}");
            rename_hexfiles($subdir);
        }
        chdir($startdir);
        // Blackboard export successfully converted
        return true;
    }
    // This is not a Blackboard export
    return true;
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
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;  
}
Ejemplo n.º 19
0
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);
}
Ejemplo n.º 20
0
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 transform()
 {
     $args = array('/_xml' => $this->xml, '/_xsl' => $this->xsl);
     $result = xslt_process($this->processor, 'arg:/_xml', 'arg:/_xsl', NULL, $args);
     if (xslt_error($this->processor) != '') {
         echo "class.XSLTransformer41.php<br>";
         echo "xslt_error:" . xslt_error($this->processor) . "<br>";
         echo "result:" . $result . "<br>";
     }
     if (strlen($result) == 0) {
         echo "class.XSLTransformer41.php<br>";
         echo "xslt_error:" . xslt_error($this->processor) . "<br>";
         echo "result:" . $result . "<br>";
     }
     if ($result) {
         $this->setOutput($result);
     } else {
         echo "class.XSLTransformer41.php<br>";
         $err = "<br/>Error: " . xslt_error($this->processor) . "<br/>Errorcode: " . xslt_errno($this->processor);
         $this->setError($err);
     }
 }
Ejemplo n.º 22
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;
        }
    }
}
Ejemplo n.º 23
0
/**
 * 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);
}
 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;
 }
Ejemplo n.º 25
0
 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;
 }
 function __applyCitationText($page_xml, $a_start, $a_end)
 {
     global $tpl;
     return true;
     $xsl = file_get_contents($tpl->tplPath . "/tpl.citation_paragraph.xsl");
     $args = array('/_xml' => $page_xml, '/_xsl' => $xsl);
     $xh = xslt_create();
     $params = array('start_id' => $a_start, 'end_id' => $a_end);
     $output = xslt_process($xh, "arg:/_xml", "arg:/_xsl", NULL, $args, $params);
     return $output;
 }
Ejemplo n.º 27
0
 /**
  * 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("&nbsp;", "&#160;", $print_output);
         $print_output = str_replace("&otimes;", "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;
 }
Ejemplo n.º 28
0
 /**
  * Use PHP4's xslt extension to do the XSL transformation
  * @param $xml mixed
  * @param $xmlType integer
  * @param $xsl mixed
  * @param $xslType integer
  * @param $resultType integer
  * @return string return type for PHP4 is always string or "false" on error.
  */
 function &_transformPHP4(&$xml, $xmlType, &$xsl, $xslType, $resultType)
 {
     $falseVar = false;
     // PHP4 doesn't support DOM
     if ($xmlType == XSL_TRANSFORMER_DOCTYPE_DOM || $xslType == XSL_TRANSFORMER_DOCTYPE_DOM || $resultType == XSL_TRANSFORMER_DOCTYPE_DOM) {
         return $falseVar;
     }
     // Create the processor
     $processor = xslt_create();
     xslt_set_encoding($processor, XSLT_PROCESSOR_ENCODING);
     // Create arguments for string types (if any)
     $arguments = array();
     if ($xmlType == XSL_TRANSFORMER_DOCTYPE_STRING) {
         $arguments['/_xml'] = $xml;
         $xml = 'arg:/_xml';
     }
     if ($xslType == XSL_TRANSFORMER_DOCTYPE_STRING) {
         $arguments['/_xsl'] = $xsl;
         $xsl = 'arg:/_xsl';
     }
     if (empty($arguments)) {
         $arguments = null;
     }
     // Do the transformation
     $resultXML = xslt_process($processor, $xml, $xsl, null, $arguments, $this->parameters);
     // Error handling
     if (!$resultXML) {
         $this->addError("Cannot process XSLT document [%d]: %s", xslt_errno($processor), xslt_error($processor));
         return $falseVar;
     }
     // DOM is not supported in PHP4 so we can always directly return the string result
     return $resultXML;
 }
Ejemplo n.º 29
0
require_once "include/xrai.inc";
set_time_limit(360);
$file = $_REQUEST["file"];
$phpfilename = "{$xml_cache}/{$file}-treeview.php";
$xmlfilename = "{$xml_documents}/{$file}.xml";
$xslfilename = "xsl/treeview.xsl";
// $do_debug = true;
$tmpfile = "";
if ($dodebug || !hasCache($xmlfilename, $xslfilename, $phpfilename) || filesize($phpfilename) == 0) {
    @unlink($phpfilename);
    //print nl2br(htmlentities("$xmlcontent"));
    if (!file_exists($xmlfilename)) {
        fatal_error("File {$xmlfilename} does not exist");
    }
    $tmpfilename = "{$phpfilename}.tmp";
    $xslp = array("baseurl" => "{$base_url}/");
    if (!@xslt_process($xslt, "{$xmlfilename}", "{$xslfilename}", "{$tmpfilename}", $params, $xslp)) {
        @unlink("{$phpfilename}.tmp");
        fatal_error("XSLT error (1): " . xslt_error($xslt));
    }
    $phpfilename_cache = $phpfilename;
    $phpfilename = $tmpfilename;
}
if (!is_file("{$phpfilename}")) {
    fatal_error("<div>Can't find processed XML file ({$phpfilename}). Please try to reload page or <a href='{$base_url}/informations.php'>report a bug</a>.</div>");
}
// set_error_handler("include_error_handler")
readfile($phpfilename);
if ($phpfilename_cache) {
    @rename("{$tmpfile}", $phpfilename_cache);
}
Ejemplo n.º 30
0
 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;
 }