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