downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

XSLTProcessor::transformToURI> <XsltProcessor::setSecurityPrefs
[edit] Last updated: Fri, 17 May 2013

view this page in

XSLTProcessor::transformToDoc

(PHP 5)

XSLTProcessor::transformToDocTransformierung in ein neues DOMDocument

Beschreibung

DOMDocument XSLTProcessor::transformToDoc ( DOMNode $doc )

Transformiert die Quellnode unter Verwendung des mittels XSLTProcessor::importStylesheet() importierten Stylesheets in ein neues DOMDocument.

Parameter-Liste

doc

Die zu verarbeitende Node.

Rückgabewerte

Das erzeugte DOMDocument oder FALSE im Falle eines Fehlers bei der Verarbeitung.

Beispiele

Beispiel #1 Transformierung in ein DOMDocument

<?php

// Laden der XML/XSL-Quelldokomente
$xml = new DOMDocument;
$xml->load('collection.xml');

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

// Prozessor instanziieren und konfigurieren
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // XSL Document importieren

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

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

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

Siehe auch



add a note add a note User Contributed Notes XSLTProcessor::transformToDoc - [1 notes]
up
0
franp at free dot fr
6 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.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites