41 $usage =
"{$argv[0]} [-h] -f <file> [-o <file>] -x <file>\n" .
44 "-f <file>: the xml input file\n" .
45 "-o <file>: optional output filepath, overwritten if exists. StdOut Default\n" .
46 "-x <file>: the xsl style sheet file to use in the transformation\n";
49 $options = getopt(
'hf:o:x:');
51 if(array_key_exists(
'h',$options))
57 if(array_key_exists(
'f',$options))
60 if(is_readable($options[
'f']))
62 $xmlFile = $options[
'f'];
66 echo
"FATAL: xml file {$options['f']} does not exist or cannot be read\n";
71 if(array_key_exists(
'o',$options))
73 $outputFile = $options[
'o'];
76 if(array_key_exists(
'x',$options))
79 if(is_readable($options[
'x']))
81 $xslFile = $options[
'x'];
85 echo
"FATAL: xsl file {$options['x']} does not exist or cannot be read\n";
96 $xsl =
new XSLTProcessor();
97 $xsldoc =
new DOMDocument();
98 $xsldoc->load($xslFile);
99 $xsl->importStyleSheet($xsldoc);
101 $xmldoc =
new DOMDocument();
102 @$xmldoc->load($xmlFile);
103 @$transformed = $xsl->transformToXML($xmldoc);
108 $OF = fopen($outputFile,
'w') or
109 die("
Fatal cannot open output file $outputFile\n");
110 $wrote = fwrite($OF, $transformed);
if(!$Test &&$OptionQ) if($stdin_flag) if($Verbose) else
Fatal($msg, $filenm, $lineno)
Write message to stdout and die.