php 的 XSLTProcessor 问题

发布于 2024-09-26 12:59:11 字数 2131 浏览 1 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失去的东西太少 2024-10-03 12:59:11

最后,我的问题解决了。 tools.xml 有一个外部 dtd 引用,

<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN"

 "../../dtd/technicalContent/dtd/concept.dtd">

默认情况下 DOMDocument 不会加载该引用,这导致了所有问题。如果您遇到同样的问题,则必须使用 LIBXML_DTDATTR 选项,例如这:

$f = 'DITA-OT1.5.1/samples/concepts/tools.xml';
$XML = new DOMDocument();
$XML->load( $f,LIBXML_DTDATTR);

Finally, my issue is solved. The tools.xml had an external dtd reference

<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN"

 "../../dtd/technicalContent/dtd/concept.dtd">

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:

$f = 'DITA-OT1.5.1/samples/concepts/tools.xml';
$XML = new DOMDocument();
$XML->load( $f,LIBXML_DTDATTR);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文