Project

Profile

Help

RE: Problem applying XSL xsl:copy-of when sub node has at... » phptest.php

Anne FAVEUR, 2018-12-19 14:39

 
1
<?php
2
function extractArguments() {
3
        global $_GET, $argv;
4
        
5
        $params = array();
6
        if(is_array($_GET) && !empty($_GET)) {
7
                        $params = $_GET;
8
        }
9
        elseif(isset($argv) && !empty($argv)) {
10
                        foreach($argv as $v) {
11
                                        $tmp = explode('=', $v);
12
                                        if(count($tmp) == 2) {
13
                                                        $params[$tmp[0]] = $tmp[1];
14
                                        }
15
                        }
16
        }
17
        return $params;
18
}
19

    
20
$params = extractArguments();
21
if(isset($params['xml']) && isset($params['xsl'])){
22

    
23
        $xmlfile = $params['xml'];
24
        $xslFile = $params['xsl'];
25
        $saxonProc = new Saxon\SaxonProcessor();
26
        $xsltProc = $saxonProc->newXsltProcessor();
27
  //$xsltProc->setProperty("dtd","false");
28
        $version = $saxonProc->version();
29
        echo 'Saxon Processor version: '.$version;
30
        echo '<br/>';
31
        $xsltProc->setSourceFromFile($xmlfile);
32
  echo 'xml error'.$xsltProc->getExceptionCount()."\n";
33
        $xsltProc->compileFromFile($xslFile);
34
  echo 'xsl error'.$xsltProc->getExceptionCount()."\n";
35
        $result = $xsltProc->transformToString();
36
  $nbError = $xsltProc->getExceptionCount();
37
  echo 'transform error'.$nbError."\n";
38
  if($nbError > 0){
39
              echo 'message' . $xsltProc->getErrorMessage(0)."\n";
40
  }
41
        if($result != null) {
42
                //file_put_contents("out/".$params["xml"],$result);
43
                echo 'exampleSimple1:';
44
                echo 'Output:'.$result;
45
        } else {
46
                echo "Result is null\n";
47
        }
48
        /*$class_methods = get_class_methods($xsltProc);
49
        foreach($class_methods as $method_name){
50
                echo "$method_name\n";
51
        }        
52
        */
53
        $xsltProc->clearParameters();
54
        $xsltProc->clearProperties();
55
}
56
else {
57
        echo "Veuillez fournir xml=xml/nom_de_xml_d_entree.xml et xsl=xsl/nom_de_la_xsl.xsl";
58
}
59
?>
(1-1/3)