Example #1
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;
}
Example #2
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;
    }
}
Example #3
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;
        }
    }
}
Example #4
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;
 }
Example #5
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;
 }
 function to_unimarc($metatdata)
 {
     //$xsl=file_get_contents("/home/ftetart/public_html/php_dev/admin/connecteurs/in/oai/dc2uni.xsl");
     /* Allocation du processeur XSLT */
     $xh = xslt_create();
     xslt_set_encoding($xh, $this->charset);
     $notice = "<?xml version='1.0' encoding='" . $this->charset . "'?>\n" . $metatdata;
     /* Traitement du document */
     $arguments = array('/_xml' => $notice, '/_xsl' => $this->xslt_transform);
     $result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
     return $result;
 }
Example #7
0
 function record_to_xml_unimarc($record, $style_sheets, $charset)
 {
     global $xslt_base_path;
     global $debug;
     if ($debug) {
         highlight_string(print_r($record, true));
     }
     //		file_put_contents('dublincoreextended1.xml', $record);
     $xh = xslt_create();
     //		echo $charset;
     xslt_set_encoding($xh, $charset);
     $result = $record;
     foreach ($style_sheets as $style_sheet) {
         if ($debug) {
             echo '<h3>' . $style_sheet . '</h3>';
         }
         /* Traitement du document */
         $arguments = array('/_xml' => $result, '/_xsl' => $style_sheet);
         $result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
         if ($debug) {
             highlight_string(print_r($result, true));
         }
         if (!$result) {
             $this->error = true;
             $this->error_message = "Sorry, notice could not be transformed by {$style_sheet} the reason is that " . xslt_error($xh) . " and the error code is " . xslt_errno($xh);
         }
     }
     xslt_free($xh);
     return $result;
 }
if (!$xslt) {
    print "<div class='error'>No XSLT processor defined !</div>";
}
print "<h1>" . htmlspecialchars($title) . "</h1>\n";
?>
 <script type='text/javascript'>
 id_pool=<?php 
echo $id_pool;
?>
;
 <? if ($todojs) print "$todojs);"; else print "todo = new Array();"; ?>
 </script>
<?

print "<div class='inex'>";
xslt_set_encoding($xslt,"UTF-8");

// Has no cache
 if (!is_file($xmlfilename)) print "<div>$xmlfilename is not a valid file ?</div>\n";
if (!is_dir("$xml_cache/$path")) {

  $result = xslt_process($xslt,$xmlfilename,"$xslfilename")  ;
   if ($result) {
//     print "<div class='warning'>No cache directory was found</div>\n";
      eval("?>" . $result . "<?");
   } else {
      exit("xslt error: " . xslt_error($xslt));
   }
}

// We do have cache
Example #9
0
<?php

$x_args = array('_xml' => $xml, '_xsl' => $xsl, '_result' => $result);
/* Reports suggest that xslt_process won't work with NULL param list */
$x_params = array('_param' => $params);
$ssheet = xslt_create();
xslt_set_encoding($ssheet, "UTF-8");
/* xslt logging options */
xslt_set_log($ssheet, 4);
xslt_set_log($ssheet, "/tmp/xslt.err");
/* Now generate the XML output file */
$xml_file = "form1.xml";
$result = xslt_process($ssheet, $xml_file, 'admin_topic.xslt', NULL, $x_args, $x_params);
print $result;
xslt_free($ssheet);