2010-06-05 1 views
1

XSL 변환을 수행 할 수없는 HTTP 사용자 에이전트가 내 서버의 리소스를 볼 수 있도록 아래 코드에서 작업하고 있습니다. transformToXML 결과가 false이기 때문에 나는 신비하지만, libxml_get_errors()의 결과는 빈 배열입니다. 보시다시피, 코드는 LibXSLT 버전 ID를 출력하고 WinVista 1.1.24 버전에서 문제가 발생합니다. libxml_get_errors()은 XSLTProcessor 개체에서 오류를 가져 오는 올바른 함수가 아닙니까? 당신은 XML 문서에 관심이 있다면transformToXML에서 반환 값이 false이고 libxml_get_errors가 아무것도 반환하지 않을 때 PHP XSLTProcessor의 문제를 찾는 방법

당신의 XML을로드하거나 실행시

 

<?php 
//redirect browsers that can handle the source files. 
if (strpos ($_SERVER ['HTTP_ACCEPT'], 'application/xhtml+xml')) { 
header ("HTTP/1.1 301 Moved Permanently"); 
header ("Location: http://" . $_SERVER ['SERVER_NAME'] . "/index.xhtml"); 
header ("Content-Type: text/text"); 
echo "\nYour browser is capable of processing the <a href='/index.xhtml'> site contents on its own."; 
die(); 
} 
//start by checking the template 
$baseDir = dirname (__FILE__); 
$xslDoc = new DOMDocument(); 
if (! $xslDoc->load ($baseDir . '/stylesheets/layout.xsl')) { 
header ("HTTP/1.1 500 Server Error"); 
header ("Content-Type: text/plain"); 
echo "\n Can't load " . $baseDir . '/stylesheets/layout.xsl'; 
die(); 
} 

//resolve the requested resource (browsers that need transformation will request the resource without the suffix) 
$uri = $_SERVER ['REQUEST_URI']; 
$len = strlen ($uri); 
if (1 >= $len || '/' == substr ($uri, $len - 1)) { 
$fileName = $baseDir . "/index.xhtml"; // use 'default' document if pathname ends in '/' 
} else { 
$fileName = $baseDir . (1 load ($fileName)) { 
header ("HTTP/1.1 500 Server Error"); 
echo "\n Can't load " . $fileName; 
die(); 
} 
// now start the XSL template processing 
$proc = new XSLTProcessor(); 
$proc->importStylesheet ($xslDoc); 
$doc = $proc->transformToXML ($xmlDoc); 
if (false === $doc) { 
header ("HTTP/1.1 500 Server Error"); 
header ("Content-Type: text/plain"); 
echo "\n"; 
// HERE is where it gets strange: the value of $doc is false and libxml_get_errors returns 0 entries. 
display_xml_errors (libxml_get_errors()); 
die(); 
} 
header ("Content-Type: text/html"); 
echo "\n"; 
echo $doc; 

function display_xml_errors($errors) { 
echo count ($errors) . " Error(s) from LibXSLT " . LIBXSLT_DOTTED_VERSION; 
for($i = 0; $i level) { 
    case LIBXML_ERR_WARNING : 
    $return .= "Warning $error->code: "; 
    break; 
    case LIBXML_ERR_ERROR : 
    $return .= "Error $error->code: "; 
    break; 
    case LIBXML_ERR_FATAL : 
    $return .= "Fatal Error $error->code: "; 
    break; 
    } 

    $return .= trim ($error->message) . "\n Line: $error->line" . "\n Column: $error->column"; 

    if ($error->file) { 
    $return .= "\n File: $error->file"; 
    } 

    echo "$return\n\n--------------------------------------------\n\n"; 
} 
} 
 
+1

감사합니다 : 당신의 error_reporting 수준

error_reporting(E_ALL | E_STRICT); // or error_reporting(-1); // overzealous, but works 

이 나있어 업그레이드합니다. 참고로 Opera는 index.xhtml을 처리 할 수 ​​있었지만 웹 서버는 application/xhtml + xml 대신 Content-Type : \ */\ *을 전송하므로 처리되지 않습니다. 쉬운 수정, 작은 오페라 지역 사회에서 많은 감사. – Wrikken

+0

@Wrikken : 마임 형 문제를 지적 해 주셔서 감사합니다. http-equiv head/meta 요소를 사용하여 Content-Type을 지정할 수있는 효과를 확인하기 위해 형식 매핑을 원숭이로 사용했습니다. – John

답변

2

내가 몇 가지 오류를 받고 있어요, 당신은 http://bobberinteractive.com/index.xhtml에서 그들을 얻을 수 .../스타일/layout.xsl XSL. 문서를 provding에 대한

PHP Warning: DOMDocument::load(): Entity 'ndash' not defined in /tmp/index.xhtml, line: 8 in /tmp/test.php on line 4 
PHP Warning: XSLTProcessor::importStylesheet(): compilation error: file /tmp/layout.xsl line 59 element a in /tmp/test.php on line 10 
PHP Warning: XSLTProcessor::importStylesheet(): Attribute 'onclick': The content is expected to be a single text node when compiling an AVT. in /tmp/test.php on line 10 
PHP Warning: XSLTProcessor::importStylesheet(): compilation error: file /tmp/layout.xsl line 185 element a in /tmp/test.php on line 10 
PHP Warning: XSLTProcessor::importStylesheet(): Attribute 'onclick': The content is expected to be a single text node when compiling an AVT. in /tmp/test.php on line 10 
PHP Warning: XSLTProcessor::transformToXml(): No stylesheet associated to this object in /tmp/test.php on line 12 
+0

새로 개발 된 오류 유형에 대해 걱정할 필요없이 과도하지 않고 개발 중에 원하는 보고서를 작성할 수 있습니다. – Wrikken

+0

오류 상수 대신 -1을 사용하는 것을 언급했습니다. –

+0

나도 그렇다 : 때로는 에러 상수가 (때때로 드물게) 추가되어 맥스 int -1이 항상 그들을 잡아낼 것이다. E_ALL은 IMHO로 작동하지 않습니다. E_REALLY_ALL을위한 시간 – Wrikken

관련 문제