3 * Script used to convert docbook source to human readable docs
5 * @copyright (c) 2007-2014 G. Giunta
8 if ($_SERVER['argc'] < 4)
9 die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n");
11 echo "Starting xsl conversion process...\n";
13 $doc = $_SERVER['argv'][1];
14 $xss = $_SERVER['argv'][2];
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");
21 // Load the XML source
22 $xml = new DOMDocument;
24 $xsl = new DOMDocument;
27 // Configure the transformer
28 $proc = new XSLTProcessor;
29 if (version_compare(PHP_VERSION,'5.4',"<"))
31 if(defined('XSL_SECPREF_WRITE_FILE'))
32 ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
36 $proc->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
38 $proc->importStyleSheet($xsl); // attach the xsl rules
40 //if ($_SERVER['argc'] >= 4)
42 if (is_dir($_SERVER['argv'][3]))
44 if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3])))
45 echo "setting param base.dir KO\n";
49 //echo "{$_SERVER['argv'][3]} is not a dir\n";
53 $out = $proc->transformToXML($xml);
54 if (!is_dir($_SERVER['argv'][3]))
55 file_put_contents($_SERVER['argv'][3], $out);