30 $usage =
"{$argv[0]} [-h] -f <file> [-o <file>] -x <file>\n" .
33 "-f <file>: the xml input file\n" .
34 "-o <file>: optional output filepath, overwritten if exists. StdOut Default\n" .
35 "-x <file>: the xsl style sheet file to use in the transformation\n";
38 $options = getopt(
'hf:o:x:');
40 if(array_key_exists(
'h',$options))
46 if(array_key_exists(
'f',$options))
49 if(is_readable($options[
'f']))
51 $xmlFile = $options[
'f'];
55 echo
"FATAL: xml file {$options['f']} does not exist or cannot be read\n";
60 if(array_key_exists(
'o',$options))
62 $outputFile = $options[
'o'];
65 if(array_key_exists(
'x',$options))
68 if(is_readable($options[
'x']))
70 $xslFile = $options[
'x'];
74 echo
"FATAL: xsl file {$options['x']} does not exist or cannot be read\n";
85 $xsl =
new XSLTProcessor();
86 $xsldoc =
new DOMDocument();
87 $xsldoc->load($xslFile);
88 $xsl->importStyleSheet($xsldoc);
90 $xmldoc =
new DOMDocument();
91 @$xmldoc->load($xmlFile);
92 @$transformed = $xsl->transformToXML($xmldoc);
97 $OF = fopen($outputFile,
'w') or
98 die("
Fatal cannot open output file $outputFile\n");
99 $wrote = fwrite($OF, $transformed);
Fatal($msg, $filenm, $lineno)
Write message to stdout and die.
if(! $Test && $OptionQ) if($stdin_flag) if($Verbose) else