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";
}
}
감사합니다 : 당신의 error_reporting 수준
이 나있어 업그레이드합니다. 참고로 Opera는 index.xhtml을 처리 할 수 있었지만 웹 서버는 application/xhtml + xml 대신 Content-Type : \ */\ *을 전송하므로 처리되지 않습니다. 쉬운 수정, 작은 오페라 지역 사회에서 많은 감사. – Wrikken@Wrikken : 마임 형 문제를 지적 해 주셔서 감사합니다. http-equiv head/meta 요소를 사용하여 Content-Type을 지정할 수있는 효과를 확인하기 위해 형식 매핑을 원숭이로 사용했습니다. – John