コード例 #1
0
ファイル: Transform.php プロジェクト: dramacode/tools
 /**
  * Transformation xsl
  */
 static function xsl($xslFile, $dom, $dest = null, $pars = null)
 {
     $xsl = new DOMDocument("1.0", "UTF-8");
     $xsl->load($xslFile);
     $proc = new XSLTProcessor();
     $proc->importStyleSheet($xsl);
     // transpose params
     if ($pars && count($pars)) {
         foreach ($pars as $key => $value) {
             $proc->setParameter('', $key, $value);
         }
     }
     // we should have no errors here
     if ($dest) {
         $proc->transformToUri($dom, $dest);
     } else {
         return $proc->transformToXML($dom);
     }
 }
コード例 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     echo "generate frontend";
     echo "\n";
     /**
      * cvmanager build
      *
      * take the xml data
      * take the xslt
      * build index.html
      */
     $xslFile = getcwd() . "/mycv.xslt";
     $xmlFile = getcwd() . "/data.xml";
     $xslDoc = new \DOMDocument();
     $xslDoc->load($xslFile);
     $xmlDoc = new \DOMDocument();
     $xmlDoc->load($xmlFile);
     $proc = new \XSLTProcessor();
     $proc->importStylesheet($xslDoc);
     $proc->transformToUri($xmlDoc, 'file://' . getcwd() . '/frontend/mycv/index.html');
 }
コード例 #3
0
 public function testTransformToUri()
 {
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/collection.xsl');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/collection.xml');
     $native = new \XSLTProcessor();
     $native->importStylesheet($xslDoc);
     $native->transformToUri($xmlDoc, 'php://temp');
     $nativeResult = file_get_contents('php://temp');
     $transpiler = new XsltProcessor();
     $transpiler->importStylesheet($xslDoc);
     $transpiler->transformToUri($xmlDoc, 'php://temp');
     $transpilerResult = file_get_contents('php://temp');
     $this->assertEquals($nativeResult, $transpilerResult);
 }
コード例 #4
0
ファイル: XsltProcessor.php プロジェクト: Samshal/xsl
 /**
  * @param DOMDocument|SimpleXMLElement $doc
  * @param string $uri
  * @return int
  */
 public function transformToUri($doc, $uri)
 {
     $styleSheet = $this->styleSheetToDomDocument();
     $transpiler = $this->createTranspiler($styleSheet);
     parent::importStylesheet($this->getTranspiledStyleSheet($transpiler, $styleSheet));
     return $transpiler->transform(function () use($doc, $uri) {
         return parent::transformToUri($doc, $uri);
     });
 }
コード例 #5
0
    $opts = new Getopt($rules);
    $opts->parse();
} catch (Console\Exception\RuntimeException $e) {
    exitWithMessage($e->getMessage(), $e->getUsageMessage(), 1);
}
if ($opts->getOption('h')) {
    exitWithMessage('tdconv <testdox.html.file.name> <output.file.name>', $opts->getUsageMessage(), 0);
}
$title = false;
$args = $opts->getArguments();
if ($opts->getOption('t')) {
    $title = $opts->getOption('t');
    unset($args['title']);
}
if (count($args) !== 2) {
    exitWithMessage('Expected exactly two arguments, got ' . count($args), $opts->getUsageMessage(), 1000);
}
$testdoxFile = $args[0];
$outputFile = $args[1];
//get the xml translation
$xsldoc = new \DOMDocument();
$xsldoc->load(dirname(__FILE__) . '/xsl/tdconv.xsl');
$xmldoc = new \DOMDocument();
$xmldoc->loadHTMLFile($testdoxFile);
$xsl = new \XSLTProcessor();
$xsl->importStyleSheet($xsldoc);
if ($title !== false) {
    $xsl->setParameter('', 'title', $title);
}
$xsl->transformToUri($xmldoc, $outputFile);