= 5) { /* PHP5 系列では、SablotによるXSLT関数は廃止されており、代わりに */ /* libxml2 + libxslt を使った、XSL関数が含まれている。*/ /* ただしサーバによってはPHP5でもXSL関数が含まれていない場合があるので注意 */ // 以下のコードはPHP5.0.2で動作したが、 // 実験段階のコードということなので、将来的に微妙に関数名が変更に // なった場合には修正を要する。 $xml = new DomDocument; $xml->loadXML(file_get_contents($target_url)); $xsl = new DomDocument; $xsl->loadXML(file_get_contents('heart.xslt')); $proc = new xsltprocessor; $proc->importStyleSheet($xsl); if ($params) { foreach ($params as $param => $value) { $proc->setParameter("", $param, $value); } } $result = $proc->transformToXML($xml); if ($result) { return $result; } else { print "Error: XSL function execution failed."; } } else if (PHP_VERSION >= 4.1) { /* PHP4.1 以降のPHP4系列の場合は、XSLT関数を使用する */ /* ただしサーバによってはPHP4系列でもXSLT関数が含まれていない場合があるので注意 */ $xh = xslt_create(); xslt_set_encoding($xh, 'utf-8'); $result = xslt_process($xh, $target_url, 'heart.xslt', NULL, NULL, $params ); if ($result) { return $result; } else { print "Error: " . xslt_error($xh) . "\n"; return ''; } } else { print "Error: PHP version too old."; return ''; } } function translate() { global $target_url, $lang; $layoutmode = 'web'; if ($_REQUEST['layout'] == 'print') { $layoutmode = 'print'; } $flipmode = '0'; if ($_REQUEST['flipmode'] == 1) { $flipmode = 1; } $params = array( 'transmode' => 'server', 'lang' => $lang, 'layoutmode' => $layoutmode, 'basefile' => $_REQUEST['target'], 'flipmode' => $flipmode, 'today' => date('Y/m/d') ); $result = process_xslt($params); if ($result) { print $result; } } ?>