PHP/XML/XSLTProcessor
Версия от 10:37, 26 мая 2010; (обсуждение)
Содержание
Load XML documents into a DOMDocument class and transform
<?
$xsl = new DOMDocument( );
$xml = new DOMDocument( );
$xsl->load("input.xsl");
$xml->load("employees.xml");
$xsltproc = new XSLTProcessor( );
$xsltproc->importStylesheet($xsl);
echo $xsltproc->transformToXML($xml);
?>
Transforming XML to HTML with XSL
<?
$xslt = new XSLTProcessor();
$xslt->importStyleSheet(DomDocument::load("rss.xsl"));
$html = $xslt->transformToDoc($rss);
$html->formatOutput = true;
print $html->saveXML();
?>
Transforming XML with XSL
<?php
if (! extension_loaded ( "xsl" )) {
dl ( "php_xsl.dll" );
}
$xslt = new xsltProcessor ( );
$xslt->importStyleSheet ( DomDocument::load ( "data.xsl" ) );
$data = new DomDocument ( "1.0", "iso-8889-1" );
$data->preserveWhiteSpace = false;
$local_file = "data.xml";
$data->load ( "http://data.org/data.xml" );
$fp = fopen ( $local_file, "wt" );
if ($fp) {
fwrite ( $fp, $data->saveXML () );
fclose ( $fp );
}
echo $xslt->transformToXML ( $data );
?>
Transforming XML with XSLT and PHP functions
<?
$dom = new DOMDocument;
$dom->loadXML("<blank/>");
$xsl = new DOMDocument;
$xsl->load("stylesheet.xsl");
$xslt = new XSLTProcessor();
$xslt->importStylesheet($xsl);
$xslt->registerPHPFunctions();
print $xslt->transformToXML($dom);
?>