3 * Script used to convert docbook source to human readable docs.
5 * @copyright (c) 2007-2015 G. Giunta
7 if ($_SERVER['argc'] < 4) {
8 die("Usage: php convert.php docbook.xml \path\\to\stylesheet.xsl output-dir|output_file\n");
10 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");
19 if (!file_exists($xss)) {
20 die("KO: file $xss cannot be found\n");
23 // Load the XML source
24 $xml = new DOMDocument();
26 $xsl = new DOMDocument();
29 // Configure the transformer
30 $proc = new XSLTProcessor();
31 if (version_compare(PHP_VERSION, '5.4', "<")) {
32 if (defined('XSL_SECPREF_WRITE_FILE')) {
33 ini_set("xsl.security_prefs", XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
36 // the php online docs only mention setSecurityPrefs, but somehow some installs have setSecurityPreferences...
37 if (method_exists('XSLTProcessor', 'setSecurityPrefs')) {
38 $proc->setSecurityPrefs(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
40 $proc->setSecurityPreferences(XSL_SECPREF_CREATE_DIRECTORY | XSL_SECPREF_WRITE_FILE);
43 $proc->importStyleSheet($xsl); // attach the xsl rules
45 //if ($_SERVER['argc'] >= 4)
47 if (is_dir($_SERVER['argv'][3])) {
48 if (!$proc->setParameter('', 'base.dir', realpath($_SERVER['argv'][3]))) {
49 echo "setting param base.dir KO\n";
52 //echo "{$_SERVER['argv'][3]} is not a dir\n";
56 $out = $proc->transformToXML($xml);
57 if (!is_dir($_SERVER['argv'][3])) {
58 file_put_contents($_SERVER['argv'][3], $out);