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