Я не могу сделать так, чтобы вот этот код работал:
PHP код:
<?php
$xp = new XsltProcessor();
// create a DOM document and load the XSL stylesheet
$xsl = new DomDocument;
$xsl->load('style.xsl');
// import the XSL styelsheet into the XSLT process
$xp->importStylesheet($xsl);
// create a DOM document and load the XML datat
$xml_doc = new DomDocument;
$xml_doc->load('content.php');
// transform the XML into HTML using the XSL file
if ($html = $xp->transformToXML($xml_doc))
{
echo $html;
}
else
{
trigger_error('XSL transformation failed.', E_USER_ERROR);
} // if
?>
// content.php
<?php
//header("Content-type: application/xml");
//header("Content-type: text/xml");
$xw = new xmlWriter();
$xw->openMemory();
$xw->startDocument('1.0','UTF-8');
$xw->startElement ('ul'); // <ul>
$xw->writeElement ('li', 'Test php Document');
$xw->writeElement ('li', 'Test xml Document');
$xw->endElement(); // </ul>
echo $xw->outputMemory(true);
?>
Вылетает с ошибкой:
Warning: DOMDocument::load() [function.DOMDocument-load]: Start tag expected, '<' not found in file:///D%3A/xampp/htdocs/Basics_xml/imho/content.php, line: 16 in D:\xampp\htdocs\Basics_xml\imho\php_handler.php on line 21
При этом если я даю этот документ то все работает.
Код:
<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<ul>
<li>Test php Document</li>
<li>Test xml Document</li>
</ul>
Это в общем-то результат вывода content.php в броузер.
Как я понимаю проблема в том, что DomDocument открывает файл как он есть, а набо бы открыть его как скрипт и взять уже результат.