public function testExcludePrefixes() { $config = new Config(); $this->assertFalse($config->shouldExcludeResultPrefixes()); $config->excludeResultPrefixes(); $this->assertTrue($config->shouldExcludeResultPrefixes()); }
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)); }
/** * @param Transpiler $transpiler * @return array */ private function createStreamOptions(Transpiler $transpiler) { $contextOptions = ['gxsl' => ['transpiler' => $transpiler]]; try { $contextOptions['gxsl']['cache'] = $this->config->getCacheAdapter(); } catch (CacheDisabledException $e) { // caching adapter is not required for the processor to run } return $contextOptions; }
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))); }
/** * @param DOMDocument $document */ public function transform(DOMDocument $document) { $root = $document->documentElement; $namespaces = FetchNamespacesFromNode::fetch($document->documentElement); $xslPrefix = array_search(XslTransformations::URI, $namespaces); $excludePrefixes = preg_split('/\\s/', $root->getAttribute('exclude-result-prefixes')); $excludePrefixes[] = 'php'; $excludePrefixes[] = 'xs'; if (in_array('#all', $excludePrefixes) === true || $this->config->shouldExcludeResultPrefixes()) { $excludePrefixes = array_merge($excludePrefixes, array_keys($namespaces)); $excludePrefixes = array_filter($excludePrefixes, function ($prefix) { return $prefix !== '#all'; }); } $excludePrefixes = array_unique($excludePrefixes); $root->setAttribute('xmlns:php', 'http://php.net/xsl'); $root->setAttribute('xmlns:xs', XmlSchema::URI); $root->setAttribute('exclude-result-prefixes', implode(' ', $excludePrefixes)); $this->transformElements($document, $xslPrefix); $this->transformAttributes($document, $xslPrefix); }
/** * @param Xpath\Compiler $xpathCompiler * @return XmlNamespaceInterface[] */ private function getNamespaces($xpathCompiler) { $namespaces = [new Xsl\XslTransformations($xpathCompiler, $this->config), new Xpath\XmlPath(), new Schema\XmlSchema()]; return array_merge($namespaces, $this->config->getExtensions()); }
public function testSetExtensions() { $config = new Config(); $config->setExtensions([new XmlSchema()]); $this->assertContainsOnlyInstancesOf(XmlSchema::class, $config->getExtensions()); }