компиляция xml+xslt в html в php - #1

druser

Новичок
компиляция xml+xslt в html в php - #1

Поиск результатов не дал, в одноименном топике тоже ничего хорошего...

написал простой скриптик, но вот появилась проблемка... может кто поскажет?

xmlxsl.php
PHP:
$domxml = new domDocument('1.0', 'WINDOWS-1251');
$domxml->appendChild($domxml->createElement('xhtml'));
$domxml->save('xhtml.xml');

define('NS', 'xsl');
$domxsl = new domDocument('1.0', 'WINDOWS-1251');
$domxsl->preserveWhiteSpace = FALSE;
$domxsl->formatOutput = TRUE;
$root = $domxsl->appendChild($domxsl->createElement(NS . ':stylesheet'));
$root->setAttribute('version', '1.0');
$root->setAttribute(NS, 'http://www.w3.org/1999/XSL/Transform');
   $output = $root->appendChild($domxsl->createElement(NS . ':output'));
   $output->setAttribute('method', 'xml');
   $output->setAttribute('encoding', 'WINDOWS-1251');
   $output->setAttribute('ident', 'yes');
   $template = $root->appendChild($domxsl->createElement(NS . ':template'));
   $template->setAttribute('match', '/');
      $html = $template->appendChild($domxsl->createElement('html'));
         $head = $html->appendChild($domxsl->createElement('head'));
            $title = $head->appendChild($domxsl->createElement('title'));
            $title->appendChild($domxsl->createTextNode(iconv('WINDOWS-1251', 'UTF-8', 'страница #1')));
$domxsl->save('xhtml.xsl');

$xsl = new xsltProcessor();
$xsl->importStylesheet($domxsl);
echo $xsl->transformtoXML($domxml);
В общем на выходе следующие ошибки:
Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: compilation error: element xsl:stylesheet in E:\Home\localhost\www\My\xmlxsl.php on line 26

Warning: XSLTProcessor::importStylesheet() [function.XSLTProcessor-importStylesheet]: xsltParseStylesheetProcess : document is not a stylesheet in E:\Home\localhost\www\My\xmlxsl.php on line 26

Warning: XSLTProcessor::transformToXml() [function.XSLTProcessor-transformToXml]: No stylesheet associated to this object in E:\Home\localhost\www\My\xmlxsl.php on line 27

Жду конструктивных предложений и замечаний по коду! Заранее спасибо! :)

ps Там где output = $root->appendChild($domxsl->createElement()) в createElement параметр NS . :eek:utput ;)
 

druser

Новичок
Автор оригинала: ТопольМ
что там?
э-э... XSLTProcessor::importStylesheet()

в смысле $xsl->importStylesheet($domxsl); (см. листинг выше)

могу для наглядности кинуть xhtml.xml и xhtml.xsl:

xhtml.xml
PHP:
<?xml version="1.0" encoding="WINDOWS-1251"?>
<xhtml/>
xhtml.xsl
PHP:
<?xml version="1.0" encoding="WINDOWS-1251"?>
<xsl:stylesheet version="1.0" xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" encoding="WINDOWS-1251" ident="yes"/>
  <xsl:template match="/">
    <html>
      <head>
        <title>страница #1</title>
      </head>
    </html>
  </xsl:template>
</xsl:stylesheet>/PHP]
 

ViJu

Новичок
правильно так
PHP:
$domxml = new domDocument('1.0', 'WINDOWS-1251');
$domxml->appendChild($domxml->createElement('xhtml'));
$domxml->save('xhtml.xml');

define('NS', 'xsl');
$domxsl = new domDocument('1.0', 'WINDOWS-1251');
$domxsl->preserveWhiteSpace = FALSE;
$domxsl->formatOutput = TRUE;
$root = $domxsl->appendChild($domxsl->createElementNS('http://www.w3.org/1999/XSL/Transform',NS . ':stylesheet'));
$root->setAttribute('version', '1.0');
$root->setAttribute(NS, 'http://www.w3.org/1999/XSL/Transform');
   $output = $root->appendChild($domxsl->createElementNS('http://www.w3.org/1999/XSL/Transform',NS . ':output'));
   $output->setAttribute('method', 'xml');
   $output->setAttribute('encoding', 'WINDOWS-1251');
   $output->setAttribute('ident', 'yes');
   $template = $root->appendChild($domxsl->createElementNS('http://www.w3.org/1999/XSL/Transform',NS . ':template'));
   $template->setAttribute('match', '/');
      $html = $template->appendChild($domxsl->createElement('html'));
         $head = $html->appendChild($domxsl->createElement('head'));
            $title = $head->appendChild($domxsl->createElement('title'));
            $title->appendChild($domxsl->createTextNode(iconv('WINDOWS-1251', 'UTF-8', 'страница #1')));
$domxsl->save('xhtml.xsl');

$xsl = new xsltProcessor();
$xsl->importStylesheet($domxsl);
echo $xsl->transformtoXML($domxml);
-~{}~ 30.06.06 21:09:

на форуме баг
как можно интерпретировать двоеточие + o за смайлик между тегов php
 
Сверху