XSLTProcessor::transformToXml

(PHP 5, PHP 7, PHP 8)

XSLTProcessor::transformToXmlTransforma em XML

Descrição

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

Transforma o nó de origem em uma string aplicando a folha de estilos fornecida pelo método xsltprocessor::importStylesheet().

Parâmetros

document

O objeto DOMDocument ou SimpleXMLElement a ser transformado.

Valor Retornado

O resultado da transformação como uma string ou false em caso de erro.

Exemplos

Exemplo #1 Transformando em uma string

<?php

// Carrega a fonte XML
$xml = new DOMDocument;
$xml->load('collection.xml');

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

// Configura o transformador
$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl); // anexa as regras xsl

echo $proc->transformToXML($xml);

?>

O exemplo acima produzirá:

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>

Veja Também

To Top