XSLTProcessor::transformToXml

(PHP 5, PHP 7, PHP 8)

XSLTProcessor::transformToXmlTransforma a XML

Descripción

publicXSLTProcessor::transformToXml(object$document): string|null|false

Transforma el nodo origen a un string aplicando la hoja de estilos dada por el método xsltprocessor::importStylesheet().

Parámetros

document

El objeto DOMDocument or SimpleXMLElement para ser transformado.

Valores devueltos

Resultado de la transformación a string o false en caso de error.

Ejemplos

Ejemplo #1 Transformando a un string

<?php

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

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

// Configura el procesador
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // adjunta las reglas XSL

echo $proc->transformToXML($xml);

?>

El resultado del ejemplo sería:

Hey! Welcome to Nicolas Eliaszewicz's sweet CD collection! <h1>Fight for your mind</h1><h2>by Ben Harper - 1995</h2><hr> <h1>Electric Ladyland</h1><h2>by Jimi Hendrix - 1997</h2><hr>

Ver también

To Top