/** * Compute <?xyl-stylesheet?> processing-instruction. * * @param \DOMDocument $ownerDocument Document that ownes PIs. * @return void */ protected function computeStylesheet(\DOMDocument $ownerDocument) { $xpath = new \DOMXPath($ownerDocument); $xyl_style = $xpath->query('/processing-instruction(\'xyl-stylesheet\')'); unset($xpath); if (0 === $xyl_style->length) { return; } for ($i = 0, $m = $xyl_style->length; $i < $m; ++$i) { $item = $xyl_style->item($i); $styleParsed = new Xml\Attribute($item->data); if (true === $styleParsed->attributeExists('href')) { $href = $this->computeLink($styleParsed->readAttribute('href'), true); if (true === $styleParsed->attributeExists('position')) { $position = max(0, (int) static::evaluateXPath(str_replace('last()', ($k = key($this->_stylesheets)) ? $k + 1 : 0, $styleParsed->readAttribute('position')))); if (isset($this->_stylesheets[$position])) { $handle = []; foreach ($this->_stylesheets as $i => $foo) { if ($position > $i) { $handle[$i] = $foo; unset($this->_stylesheets[$i]); } else { break; } } $handle[$position] = $href; foreach ($this->_stylesheets as $i => $foo) { if ($i === $position) { $handle[$position = $i + 1] = $foo; unset($this->_stylesheets[$i]); } else { break; } } $this->_stylesheets = $handle + $this->_stylesheets; } else { $this->_stylesheets[$position] = $href; ksort($this->_stylesheets, SORT_NUMERIC); } } else { $this->_stylesheets[] = $href; } } $ownerDocument->removeChild($item); unset($styleParsed); } return; }
/** * Compute <?xyl-link?> processing-instruction. * * @param \DOMDocument $ownerDocument Document that ownes PIs. * @return void */ protected function computeDocumentLinks(\DOMDocument $ownerDocument) { $xpath = new \DOMXPath($ownerDocument); $xyl_link = $xpath->query('/processing-instruction(\'xyl-link\')'); unset($xpath); if (0 === $xyl_link->length) { return; } for ($i = 0, $m = $xyl_link->length; $i < $m; ++$i) { $item = $xyl_link->item($i); $documentLink = new Xml\Attribute($item->data); if (true === $documentLink->attributeExists('href')) { $documentLink->writeAttribute('href', $this->computeLink($documentLink->readAttribute('href'), true)); } $this->_documentLinks[] = $documentLink; $ownerDocument->removeChild($item); } return; }