XSLTProcessor::transformToDoc

(PHP 5, PHP 7, PHP 8)

XSLTProcessor::transformToDocDönüşüm sonucunu bir DOMDocument olarak döndürür

Açıklama

public XSLTProcessor::transformToDoc(object $belge, string|null $dönenSınıf = null): DOMDocument|false

xsltprocessor::importStylesheet() yöntemi ile belirtilen biçembendi belirtilen belgeye uygulayarak kaynak düğümünü bir DOMDocument nesnesine dönüştürür.

Değiştirgeler

belge

Dönüştürülecek belge.

Dönen Değerler

Bir hata oluşursa false aksi takdirde bir DOMDocument nesnesi döner.

Örnekler

Örnek 1 - Bir DOMDocument nesnesine dönüşüm

<?php

// XML belgeyi yükleyelim
$xml = new DOMDocument;
$xml->load('collection.xml');

$xsl = new DOMDocument;
$xsl->load('collection.xsl');

// Dönüştürücüyü yapılandıralım
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // XSL kuralları

echo trim($proc->transformToDoc($xml)->firstChild->wholeText);

?>

Yukarıdaki örneğin çıktısı:

Hey! Welcome to Nicolas Eliaszewicz's sweet CD collection!

Ayrıca Bakınız

add a note add a note

User Contributed Notes 1 note

up
1
franp at free dot fr
17 years ago
In most cases if you expect XML (or XHTML) as output you better use transformToXML() directly. You gain better control over xsl:output attributes, notably omit-xml-declaration.

Instead of :
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$dom = $proc->transformToDoc($xml);
echo $dom->saveXML();

do use :
$proc = new XSLTProcessor();
$proc->importStylesheet($xsl);
$newXml = $proc->transformToXML($xml);
echo $newXml;

In the first case, <?xml version="1.0" encoding="utf-8"?> is added whatever you set the omit-xml-declaration while transformToXML() take the attribute into account.
To Top