我正在尝试使用Php XSLTProcessor 将XSL-FO文件转换为HTML。 我在这做什么:
public static function toHTML($xml)
{
// init
$xp = new XSLTProcessor();
$xmlDoc = new Mv_Dom_Document();
$xmlDoc->loadXML($xml);
$dirXslt = $GLOBALS['G_config']['XSLT_STYLESHEETS'].'fo2html/';
$aXsltSS = GestionFichiers::getDirContent($dirXslt);
// chargement des feuilles de styles XSLT pour la conversion
foreach ($aXsltSS AS $stylesheet) {
$xslDoc = new Mv_Dom_Document($stylesheet->getRealPath());
$xp->importStylesheet($xslDoc);
unset($xslDoc);
}
// transformation HTML > XML
return $xp->transformToXML($xmlDoc);
}
但转换时出现以下错误:
ERREUR - XSLTProcessor::transformToXml() [<a href='xsltprocessor.transformtoxml'>xsltprocessor.transformtoxml</a>]: xsltApplySequenceConstructor: apply-templates was not compiled
ERREUR - XSLTProcessor::transformToXml() [<a href='xsltprocessor.transformtoxml'>xsltprocessor.transformtoxml</a>]: xsltApplySequenceConstructor: apply-templates was not compiled
ERREUR - XSLTProcessor::transformToXml() [<a href='xsltprocessor.transformtoxml'>xsltprocessor.transformtoxml</a>]: xsltApplySequenceConstructor: if was not compiled
当我尝试直接使用apache fop扩展来转换我的XSL-FO时,转换成功,那么为什么php会失败?
PS:当我尝试使用XSLTProcessor转换其他内容时,作为带有正确样式表的HTML2FO,我没有遇到任何问题。
先谢谢。
编辑: 样式表已经从http://svn.apache.org/repos/asf/db/derby/docs/trunk/lib/fo2html.xsl上的apache svn下载了,这里输入的样本我一直用于测试:
<?xml version="1.0" encoding="UTF-8"?>
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format" line-stacking-strategy="font-height">
<fo:layout-master-set>
<fo:simple-page-master margin-bottom="35.4pt" margin-left="27pt" margin-right="19.3pt" margin-top="35.4pt" master-name="pm0" page-height="841.9pt" page-width="595.3pt">
<fo:region-body margin-bottom="-17.4pt" margin-top="-17.4pt" overflow="visible" region-name="body"/>
<fo:region-before extent="771.1pt" overflow="visible" region-name="header"/>
<fo:region-after display-align="after" extent="771.1pt" overflow="visible" region-name="footer"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="pm0" orphans="2" white-space-collapse="false" widows="2">
<fo:flow flow-name="body">
<fo:block end-indent="0pt" line-height="13.7pt" start-indent="0pt" text-align="start" text-indent="0pt">
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format" role="html:body" font-family="Times Roman, serif" font-size="12pt">
<fo:inline role="html:span" font-weight="bold">
<fo:inline text-decoration="underline" role="html:u">Informations sur le patient</fo:inline>
</fo:inline>
</fo:block>
</fo:block>
<fo:block line-height="13.7pt">
<fo:leader line-height="13.7pt"/>
</fo:block>
<fo:block line-height="13.7pt">
<fo:leader line-height="13.7pt"/>
</fo:block>
<fo:block end-indent="0pt" line-height="11.4pt" start-indent="0pt" text-align="start" text-indent="0pt">
<fo:inline font-family="Times Roman, serif" font-size="10pt">
<fo:inline role="html:body" font-weight="bold">
idPATIENT :
</fo:inline>
<fo:inline role="html:body">
1
</fo:inline>
</fo:inline>
</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>