Exemple #1
0
 public function testWithConfig()
 {
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/collection.xsl');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/collection.xml');
     $decorator = new XsltProcessor(new Config());
     $decorator->importStyleSheet($xslDoc);
     $this->assertGreaterThan(1, strlen($decorator->transformToXML($xmlDoc)));
 }
 public function testMultipleMethod()
 {
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/combine-multiple-functions.xsl');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/combine-multiple-functions.xml');
     $processor = new XsltProcessor();
     $processor->importStylesheet($xslDoc);
     $processorResult = $processor->transformToXML($xmlDoc);
     $this->assertEquals(157, trim($processorResult));
 }
Exemple #3
0
 protected function transformFile($path, array $parameters = [])
 {
     $styleSheet = new DOMDocument();
     $styleSheet->load($path);
     $processor = new XsltProcessor();
     $processor->importStyleSheet($styleSheet);
     foreach ($parameters as $key => $value) {
         $processor->setParameter('', $key, $value);
     }
     $document = new DOMDocument();
     $document->load('Stubs/collection.xml');
     return trim($processor->transformToXml($document));
 }
Exemple #4
0
 public function testMethod()
 {
     $extension = new MyExtension();
     $config = new Config();
     $config->addExtension($extension);
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/method.xsl');
     $xslDoc->documentElement->setAttribute('version', '1.0');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/collection.xml');
     $processor = new XsltProcessor($config);
     $processor->importStylesheet($xslDoc);
     $processorResult = $processor->transformToXML($xmlDoc);
     $this->assertEquals('24', trim($processorResult));
 }
 public function testExcludePrefixesAll()
 {
     $xslDoc = new DOMDocument("1.0", "UTF-8");
     $xslRoot = $xslDoc->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:stylesheet');
     $xslRoot->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:php', 'http://php.net/xsl');
     $xslRoot->setAttribute('exclude-result-prefixes', '#all');
     $xslRoot->setAttribute('version', '1.0');
     $xslDoc->appendChild($xslRoot);
     $include = $xslDoc->createElementNS('http://www.w3.org/1999/XSL/Transform', 'xsl:include');
     $include->setAttribute('href', getcwd() . '/Stubs/include3.xsl');
     $xslRoot->appendChild($include);
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/combine-multiple-functions.xml');
     $transpiler = new XsltProcessor();
     $transpiler->importStylesheet($xslDoc);
     $transpilerResult = $transpiler->transformToXML($xmlDoc);
     $this->assertEquals(157, trim($transpilerResult));
 }
Exemple #6
0
 public function testCache()
 {
     $arrayCache = new ArrayAdapter();
     $config = new Config();
     $config->setCacheAdapter(new SimpleCallbackAdapter($arrayCache));
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/combine-multiple-functions.xsl');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/combine-multiple-functions.xml');
     $processor = new XsltProcessor($config);
     $processor->importStylesheet($xslDoc);
     $processorResult = $processor->transformToXML($xmlDoc);
     $cacheKey = dirname(__DIR__) . '/Stubs/combine-multiple-functions.xsl';
     $cache = $arrayCache->get($cacheKey);
     $this->assertEquals(157, trim($processorResult));
     $this->assertNotNull($cache);
     $cache = str_replace('floor', 'ceiling', $cache);
     $arrayCache->set($cacheKey, $cache);
     $this->assertEquals(158, trim($processor->transformToXML($xmlDoc)));
 }
 public function testBug12()
 {
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/item-types.xsl');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/item-types.xml');
     $native = new \XSLTProcessor();
     $native->importStylesheet($xslDoc);
     $nativeResult = $native->transformToXML($xmlDoc);
     $transpiler = new XsltProcessor();
     $transpiler->importStylesheet($xslDoc);
     $transpilerResult = $transpiler->transformToXML($xmlDoc);
     $this->assertEquals($nativeResult, $transpilerResult);
 }
Exemple #8
0
 public function testByAttributeValueTemplates()
 {
     $styleSheet = new DOMDocument();
     $styleSheet->load('Stubs/Xsl/ForEachGroup/group-by-avt.xsl');
     $processor = new XsltProcessor();
     $processor->importStyleSheet($styleSheet);
     $data = new DOMDocument();
     $data->load('Stubs/packages.xml');
     $this->assertEquals('<span title="1 CAMT packages for key Genkgo">CAMT</span>', trim($processor->transformToXml($data)));
 }
 public function testAmpersandEscaped()
 {
     $xslDoc = new DOMDocument();
     $xslDoc->load('Stubs/ampersand-escaped.xsl');
     $xmlDoc = new DOMDocument();
     $xmlDoc->load('Stubs/collection.xml');
     $native = new \XSLTProcessor();
     $native->importStylesheet($xslDoc);
     $native->registerPHPFunctions();
     $nativeResult = trim($native->transformToXML($xmlDoc));
     $transpiler = new XsltProcessor();
     $transpiler->importStylesheet($xslDoc);
     $transpiler->registerPHPFunctions();
     $transpilerResult = trim($transpiler->transformToXML($xmlDoc));
     $this->assertEquals($nativeResult, $transpilerResult);
 }