PHP 8.1.28 Released!

XSLTProcessor::transformToDoc

(PHP 5, PHP 7, PHP 8)

XSLTProcessor::transformToDocBelgeyi dönüştürür

Açıklama

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

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

Bağımsız Değişkenler

belge

Dönüştürülecek DOMDocument veya SimpleXMLElement nesnesi ya da libxml uyumlu nesne.

dönenSınıf

Bu isteğe bağlı bağımsız değişken XSLTProcessor::transformToDoc() işlevinin belirtilen sınıfın nesnesini döndürmekte kullanılabilir. Bu sınıf ya belge sınıfı ile aynı olmalı ya da belge sınıfına bir genişletme olmalıdır.

Dönen Değerler

Bir hata oluşursa false aksi takdirde sonuçlanan belge 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

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