3e80791a172c4564d16089b003a6a6e05ab5cc03
[plcapi.git] / doc / convert.php
1 <?php
2 /**
3  * Script used to convert docbook source to human readable docs
4  *
5  * @copyright (c) 2007-2013 G. Giunta
6  */
7
8 if ($_SERVER['argc'] < 4)
9   die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n");
10 else
11   echo "Starting xsl conversion process...\n";
12
13 $doc = $_SERVER['argv'][1];
14 $xss = $_SERVER['argv'][2];
15
16 if (!file_exists($doc))
17   die("KO: file $doc cannot be found\n");
18 if (!file_exists($xss))
19   die("KO: file $xss cannot be found\n");
20
21 // Load the XML source
22 $xml = new DOMDocument;
23 $xml->load($doc);
24 $xsl = new DOMDocument;
25 $xsl->load($xss);
26
27 // Configure the transformer
28 $proc = new XSLTProcessor;
29 $proc->importStyleSheet($xsl); // attach the xsl rules
30
31 //if ($_SERVER['argc'] >= 4)
32 //{
33   if (is_dir($_SERVER['argv'][3]))
34   {
35
36     if (!$proc->setParameter('', 'base.dir', $_SERVER['argv'][3]))
37       echo "setting param base.dir KO\n";
38   }
39   else
40   {
41     //echo "{$_SERVER['argv'][3]} is not a dir\n";
42   }
43 //}
44   $out = $proc->transformToXML($xml);
45   if (!is_dir($_SERVER['argv'][3]))
46     file_put_contents($_SERVER['argv'][3], $out);
47
48 echo "OK\n";
49 ?>