Project

Profile

Help

Bug #2055 » xsltExamples.php

O'Neil Delpratt, 2014-04-17 12:36

 
1
<?php 
2
            
3
            /* simple example to show transforming to string */
4
            function exampleSimple1($proc, $xmlfile, $xslFile){
5
                $proc->setSourceFile($xmlfile);
6
                $proc->setStylesheetFile($xslFile);
7
                        
8
                $result = $proc->transformToString();               
9
                if($result != null) {               
10
                  $result;
11
                } else {
12
                  $errCount = $proc->getExceptionCount();
13
                  if($errCount > 0 ){
14
                    for ($i = 0; $i < $errCount; $i++) {
15
                    $errC = $proc->getErrorCode(intval($i));
16
                    $errMessage = $proc->getErrorMessage(intval($i));
17
                    if($errC != NULL) {
18
                        echo 'Error found: '. $errC.' :'.$errMessage;        
19
                    }
20
                    $proc->exceptionClear();
21
                  }
22
                }
23
                }
24
                $proc->clearParameters();
25
                $proc->clearProperties();            
26
                return $result;
27
            }
28
            
29
      
30
            $data = array();
31
            for ($i = 0; $i < $_REQUEST['i']; $i++) {
32
            
33
              $usage = array();
34
              $usage[] = memory_get_usage();
35
              $proc = new SaxonProcessor();
36
              $usage[] = memory_get_usage();
37

    
38
              exampleSimple1($proc, 'input.xml', 'template.xsl');
39
              $usage[] = memory_get_usage();
40
              $proc->close();            
41
              $usage[] = memory_get_usage();
42
              unset($proc);
43
              $usage[] = memory_get_usage();
44
              $data[$i] = $usage;
45
            }
46

    
47
            ?>
48

    
49
        <html><head>
50
        </head>
51
        <body>
52
          <table>
53
            <thead>
54
              <tr>
55
                <th>step ID</th>
56
                <th>before Saxon INIT</th>
57
                <th>after Saxon INIT</th>
58
                <th>After transformation</th>
59
                <th>After close()</th>
60
                <th>After unset()</th>
61
              <tr>
62
             </thead>
63
             <tbody>
64
              <?php foreach ($data as $rowId => $row):?>
65
                <tr>
66
                  <td><?=$rowId?></td>
67
                  <?php foreach ($row as $val):?>
68
                    <td><?=$val?></td>
69
                  <?php endforeach;?>
70
                </tr>
71
              <?php endforeach;?>
72
             </tbody>
73
             </table>
74
        </body>
75
        </html>
76

    
(1-1/2)