سؤال

أحاول استخدام XSLTProcessor فئة في PHP لإنشاء XHTML من ملف .dita استنادًا إلى DITA Open Toolkitملفات XSLT.

يعمل XSLTProcessor مع ملفات XML و XSLT بسيطة (على سبيل المثال مع عينات على ويكيبيديا) ، لكنها تفشل مع XSLs الخاصة بمجموعة الأدوات المفتوحة.

الجزء المتناسب هو أن كل شيء يعمل بشكل جيد ، إذا كنت أستخدم الأمر XSLTProc من Bash على نفس الكمبيوتر على نفس الملفات (لم أستخدم أي مفاتيح).

لذا ، هذا هو الكود الخاص بي:

<?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.

أي أفكار ما هو الخطأ؟

هل كانت مفيدة؟

المحلول

أخيرًا ، تم حل مشكلتي. كان لدى tools.xml مرجع DTD خارجي

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

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

لم يتم تحميل Wich بواسطة DomDocument بشكل افتراضي ، وهذا تسبب في جميع المشكلات. إذا كان لديك نفس المشكلة ، فيجب عليك استخدام libxml_dtdattr خيار مثل هذا:

$f = 'DITA-OT1.5.1/samples/concepts/tools.xml';
$XML = new DOMDocument();
$XML->load( $f,LIBXML_DTDATTR);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top