php 的 XSLTProcessor 问题
我正在尝试在 php 中使用 XSLTProcessor 类 从 .基于 DITA Open Toolkit 的 xslt 文件的 dita 文件。
XSLTProcessor 正在处理简单的 xml 和 xslt 文件(例如,使用维基百科上的示例),但 Open Toolkit 的 xsls 失败了。
有趣的是,如果我在同一台计算机上的相同文件上使用 bash 中的 xsltproc 命令,一切都会正常运行(我没有使用任何开关)。
所以,这是我的代码:
<?php
$sXML = file_get_contents('concepts/tools.xml');
# LOAD XML FILE
$XML = new DOMDocument();
$XML->loadXML( $sXML );
# START XSLT
$xslt = new XSLTProcessor();
$XSL = new DOMDocument();
$XSL->load( 'xsl/dita2xhtml.xsl');
$xslt->importStylesheet( $XSL );
#PRINT
print $xslt->transformToXML( $XML );
我得到的不是有效的 xhtml 文件,而是这样的输出:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE span PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<span style="background-color: yellow;"><span style="font-weight: bold">[/concept
{""}) </span>
<span style="background-color: yellow;"><span style="font-weight: bold">[/concept/title
{""}) </span>Tools<span style="font-weight: bold"> (title]</span></span>
<span style="background-color: yellow;"><span style="font-weight: bold">[/concept/shortdesc
{""}) </span>Invest in a good set of tools for doing all kinds of tasks around the house.<span style="font-weight: bold"> (shortdesc]</span></span>
<span style="background-color: yellow;"><span style="font-weight: bold">[/concept/conbody
{""}) </span><span style="background-color: yellow;"><span style="font-weight: bold">[/concept/conbody/p
{""}) </span>Useful tools include the following items:<span style="font-weight: bold"> (p]</span></span> (...)
这只是输出的第一部分,但我不想在此处复制整个文本。
xsl 文件和 dita 概念文件都来自 DITA Open Toolkit。
任何想法有什么问题吗?
I'm trying to use the XSLTProcessor class in php to generate xhtml from a .dita file based on the DITA Open Toolkit's xslt files.
The XSLTProcessor is working with simple xml and xslt files (e.g. with the samples on wikipedia), but it fails with the Open Toolkit's xsls.
The intresting part is that everything works well, if I use xsltproc command from bash on the same computer on the same files (I used no switches).
So, here's my code:
<?php
$sXML = file_get_contents('concepts/tools.xml');
# LOAD XML FILE
$XML = new DOMDocument();
$XML->loadXML( $sXML );
# START XSLT
$xslt = new XSLTProcessor();
$XSL = new DOMDocument();
$XSL->load( 'xsl/dita2xhtml.xsl');
$xslt->importStylesheet( $XSL );
#PRINT
print $xslt->transformToXML( $XML );
And instead of a valid xhtml file I get an output like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE span PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<span style="background-color: yellow;"><span style="font-weight: bold">[/concept
{""}) </span>
<span style="background-color: yellow;"><span style="font-weight: bold">[/concept/title
{""}) </span>Tools<span style="font-weight: bold"> (title]</span></span>
<span style="background-color: yellow;"><span style="font-weight: bold">[/concept/shortdesc
{""}) </span>Invest in a good set of tools for doing all kinds of tasks around the house.<span style="font-weight: bold"> (shortdesc]</span></span>
<span style="background-color: yellow;"><span style="font-weight: bold">[/concept/conbody
{""}) </span><span style="background-color: yellow;"><span style="font-weight: bold">[/concept/conbody/p
{""}) </span>Useful tools include the following items:<span style="font-weight: bold"> (p]</span></span> (...)
It's just the first part of the output, but I didn't want copy the whole text here.
Both the xsl file and dita concept file is from the DITA Open Toolkit.
Any ideas what's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,我的问题解决了。 tools.xml 有一个外部 dtd 引用,
默认情况下 DOMDocument 不会加载该引用,这导致了所有问题。如果您遇到同样的问题,则必须使用 LIBXML_DTDATTR 选项,例如这:
Finally, my issue is solved. The tools.xml had an external dtd reference
wich wasn't loaded by the DOMDocument by default, and that caused all the problems. If you have the same problem, you have to use the LIBXML_DTDATTR option like this: