XSLTProcessor::transformToDoc

(PHP 5, PHP 7, PHP 8)

XSLTProcessor::transformToDocTransforma en un documento

Descripción

publicXSLTProcessor::transformToDoc(object$document, ?string$returnClass = null): object|false

Transforma el nodo origen en un documento (e.g. DOMDocument) aplicando las hojas de estilo dadas por el método XSLTProcessor::importStylesheet().

Parámetros

document

The DOMDocument or SimpleXMLElement or libxml-compatible object to be transformed.

returnClass

This optional parameter may be used so that XSLTProcessor::transformToDoc() will return an object of the specified class. That class should either extend or be the same class as document's class.

Valores devueltos

El documento resultante o false en caso de error.

Ejemplos

Ejemplo #1 Transformando en un DOMDocument

<?php

// Carga del fichero origen XML
$xml = new DOMDocument;
$xml->load('collection.xml');

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

// Configuración del procesador
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // adjunta las reglas xsl

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

?>

El resultado del ejemplo sería:

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

Ver también

To Top