Creates XSL stylesheet and parses XML+XSL using Xml/Conversion.

@todo   Allow changing of encoding

@param DomDocument $xmldom XML-data as DomDocument

@return string Parsed data as string

@uses   DomDocument
517606
public function parse($xmldom) : string
    {
        if (!$this->templatePreProcessed) {
            $this->preProcessTemplate();
        }

        $conversion = new Conversion($xmldom);
        $styles[0] = $this->getPreProcessedTemplateDom();
        $conversion->addStylesheet($styles);

        return (string) $conversion->toString();
    }
202791
private function createRawXmlDocument()
    {
        $xmlDocument = new \DOMDocument;
        $xmlDocument->encoding = 'UTF-8';
        $xmlDocument->strictErrorChecking = false;
        $xmlDocument->formatOutput = true;
        $libXmlState = libxml_use_internal_errors(true);
        $xmlDocument->loadHTML($this->getUnifiedHtml());
        libxml_clear_errors();
        libxml_use_internal_errors($libXmlState);
        $xmlDocument->normalizeDocument();

        return $xmlDocument;
    }
212805
function domString( $domDocument )
    {
        $ini = eZINI::instance();
        $xmlCharset = $ini->variable( 'RegionalSettings', 'ContentXMLCharset' );
        if ( $xmlCharset == 'enabled' )
        {
            $charset = eZTextCodec::internalCharset();
        }
        else if ( $xmlCharset == 'disabled' )
            $charset = true;
        else
            $charset = $xmlCharset;
        if ( $charset !== true )
        {
            $charset = eZCharsetInfo::realCharsetCode( $charset );
        }
        $domString = $domDocument->saveXML();
        return $domString;
    }
1021995
protected function process(\DOMDocument $xmlDocument)
    {
        $xPath = new \DOMXPath($xmlDocument);
        $this->clearAllCaches();
        $this->purgeVisitedNodes();
        set_error_handler([$this, 'handleXpathQueryWarnings'], E_WARNING);

        $this->normalizeStyleAttributesOfAllNodes($xPath);

        // grab any existing style blocks from the html and append them to the existing CSS
        // (these blocks should be appended so as to have precedence over conflicting styles in the existing CSS)
        $allCss = $this->css;
        if ($this->isStyleBlocksParsingEnabled) {
            $allCss .= $this->getCssFromAllStyleNodes($xPath);
        }

        $cssParts = $this->splitCssAndMediaQuery($allCss);
        $excludedNodes = $this->getNodesToExclude($xPath);
        $cssRules = $this->parseCssRules($cssParts['css']);
        foreach ($cssRules as $cssRule) {
            // There's no real way to test "PHP Warning" output generated by the following XPath query unless PHPUnit
            // converts it to an exception. Unfortunately, this would only apply to tests and not work for production
            // executions, which can still flood logs/output unnecessarily. Instead, Emogrifier's error handler should
            // always throw an exception and it must be caught here and only rethrown if in debug mode.
            try {
                // \DOMXPath::query will always return a DOMNodeList or an exception when errors are caught.
                $nodesMatchingCssSelectors = $xPath->query($this->translateCssToXpath($cssRule['selector']));
            } catch (\InvalidArgumentException $e) {
                if ($this->debug) {
                    throw $e;
                }
                continue;
            }

            /** @var \DOMElement $node */
            foreach ($nodesMatchingCssSelectors as $node) {
                if (in_array($node, $excludedNodes, true)) {
                    continue;
                }
                // if it has a style attribute, get it, process it, and append (overwrite) new stuff
                if ($node->hasAttribute('style')) {
                    // break it up into an associative array
                    $oldStyleDeclarations = $this->parseCssDeclarationsBlock($node->getAttribute('style'));
                } else {
                    $oldStyleDeclarations = [];
                }
                $newStyleDeclarations = $this->parseCssDeclarationsBlock($cssRule['declarationsBlock']);
                $node->setAttribute(
                    'style',
                    $this->generateStyleStringFromDeclarationsArrays($oldStyleDeclarations, $newStyleDeclarations)
                );
            }
        }

        if ($this->isInlineStyleAttributesParsingEnabled) {
            $this->fillStyleAttributesWithMergedStyles();
        }

        if ($this->shouldMapCssToHtml) {
            $this->mapAllInlineStylesToHtmlAttributes($xPath);
        }

        if ($this->shouldKeepInvisibleNodes) {
            $this->removeInvisibleNodes($xPath);
        }

        $this->removeImportantAnnotationFromAllInlineStyles($xPath);

        $this->copyCssWithMediaToStyleNode($xmlDocument, $xPath, $cssParts['media']);

        restore_error_handler();
    }
763064
public static function fromXml(\DOMDocument $xml)
    {
        $static = new static();

        $loans = $xml->getElementsByTagName('loan');
        $static->loans = LoanCollection::fromXml($loans);

        $loanHistory = $xml->getElementsByTagName('loanHistory');
        $static->loanHistory = LoanCollection::fromXml($loanHistory);

        $holds = $xml->getElementsByTagName('hold');
        $static->holds = HoldCollection::fromXml($holds);

        $expenses = $xml->getElementsByTagName('fine');
        $static->expenses = ExpenseCollection::fromXml($expenses);

        $totalFine = $xml->getElementsByTagName('totalFine');
        $static->totalFine = FloatLiteral::fromXml($totalFine);

        $totalCost = $xml->getElementsByTagName('totalCost');
        $static->totalCost = FloatLiteral::fromXml($totalCost);

        $message = $xml->getElementsByTagName('message');
        $static->message = StringLiteral::fromXml($message);

        $loanHistoryConfig = $xml->getElementsByTagName('loanHistoryConfigurable');
        $static->loanHistoryConfigurable = BoolLiteral::fromXml($loanHistoryConfig);

        return $static;
    }
1307466
public function toXML(DOMDocument $doc, $nodeName = "")
    {
        $node = $doc->createElement($nodeName);
        $text = $doc->createTextNode($this->value);
        $node->appendChild($text);
        return $node;
    }
524365
public function asDom(): \DOMDocument
    {
        $doc = new \DOMDocument();
        $doc->loadXML($this->writer->outputMemory());
        return $doc;
    }
707234
public function convert(DOMDocument $document)
    {
        $xpath = new DOMXPath($document);
        $xpathExpression = '//ns:pre';
        $ns = $document->documentElement->namespaceURI;
        $xpath->registerNamespace('ns', $ns);
        $elements = $xpath->query($xpathExpression);

        foreach ($elements as $element) {
            $element->textContent = str_replace(']]>', ']]]]><![CDATA[>', $element->textContent);
        }

        return $document;
    }
216030
public static function htmlToDomDocument($html)
    {
        if (!$html) {
            $html = '';
        }

        // Transform multibyte entities which otherwise display incorrectly.
        $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');

        // Internal errors enabled as HTML5 not fully supported.
        libxml_use_internal_errors(true);

        // Instantiate new DOMDocument object, and then load in UTF-8 HTML.
        $dom = new DOMDocument();
        $dom->encoding = 'UTF-8';
        $dom->loadHTML("<div>$html</div>");

        return $dom;
    }
986805
public function convert(DOMDocument $document)
    {
        foreach ($this->converters as $converter) {
            $converter->convert($document);
        }

        return $document;
    }
1253294
protected function renderXml($data)
    {
        $xml = $this->arrayToXml($data);

        $dom = new \DOMDocument('1.0');
        $dom->preserveWhiteSpace = false;
        $dom->formatOutput = $this->pretty;
        $dom->loadXML($xml->asXML());

        return $dom->saveXML();
    }
384866
public function asDOM()
	{
		$xml = '<xsl:template xmlns:xsl="http://www.w3.org/1999/XSL/Transform">'
		     . $this->__toString()
		     . '</xsl:template>';

		$dom = new TemplateDocument($this);
		$dom->loadXML($xml);

		return $dom;
	}
668066
public function getXML(\DOMDocument $document)
    {
        $xml = $document->createElement('ns1:Payment');

        if (!empty($this->hostedDataId)) {
            $hostedDataId = $document->createElement('ns1:HostedDataID');
            $hostedDataId->textContent = $this->hostedDataId;

            $xml->appendChild($hostedDataId);
        }

        if (!empty($this->amount)) {
            $amount                = $document->createElement('ns1:ChargeTotal');
            $amount->textContent   = $this->amount;
            $currency              = $document->createElement('ns1:Currency');
            $currency->textContent = self::CURRENCY_EUR;

            $xml->appendChild($amount);
            $xml->appendChild($currency);
        }

        return $xml;
    }
1061468
public function convert($xmlString) {

        $dom = new \DOMDocument ();
        $dom->loadXML($xmlString);

        $documentElement = $dom->documentElement;
        return $documentElement ? $this->convertDOM($dom->documentElement) : $xmlString;
    }
817297
public function toUnsignedXML() : DOMElement
    {
        $this->document = DOMDocumentFactory::create();

        $root = $this->document->createElementNS(Constants::NS_SAMLP, 'samlp:'.$this->tagName);
        $this->document->appendChild($root);

        /* Ugly hack to add another namespace declaration to the root element. */
        $root->setAttributeNS(Constants::NS_SAML, 'saml:tmp', 'tmp');
        $root->removeAttributeNS(Constants::NS_SAML, 'tmp');

        $root->setAttribute('ID', $this->id);
        $root->setAttribute('Version', '2.0');
        $root->setAttribute('IssueInstant', gmdate('Y-m-d\TH:i:s\Z', $this->issueInstant));

        if ($this->destination !== null) {
            $root->setAttribute('Destination', $this->destination);
        }
        if ($this->consent !== Constants::CONSENT_UNSPECIFIED) {
            $root->setAttribute('Consent', $this->consent);
        }

        if ($this->issuer !== null) {
            $this->issuer->toXML($root);
        }

        Extensions::addList($root, $this->extensions);

        return $root;
    }
667631
public function parseXML(\SimpleXMLElement $xml)
    {
        $name = $xml->getName();
        if ($name !== 'svg') {
            return null;
        }

        $width = isset($xml['width']) ? $xml['width'] : null;
        $height = isset($xml['height']) ? $xml['height'] : null;
        $namespaces = $xml->getNamespaces(true);

        $img = new SVG($width, $height, $namespaces);

        $nsKeys = array_keys($namespaces);

        $doc = $img->getDocument();
        $this->applyAttributes($doc, $xml, $nsKeys);
        $this->applyStyles($doc, $xml);
        $this->addChildren($doc, $xml, $nsKeys);

        return $img;
    }
527800
public static function save(DOMDocument $dom)
	{
		$xml = self::innerXML($dom->documentElement);
		if (strpos($xml, 'xmlns:xsl') !== false)
		{
			$xml = preg_replace('((<[^>]+?) xmlns:xsl="' . self::XMLNS_XSL . '")', '$1', $xml);
		}

		return $xml;
	}