Question

Je suis en train d'utiliser la classe XSLTProcessor en php pour générer xhtml à partir d'un fichier .dita basé sur le DITA Open Toolkit les fichiers xslt de '.

Le XSLTProcessor travaille avec de simples fichiers xml et xslt (par exemple, avec les échantillons sur wikipedia), mais il échoue avec les XSL de la boîte à outils ouverte.

La partie intresting est que tout fonctionne bien, si j'utilise la commande xsltproc de bash sur le même ordinateur sur les mêmes fichiers (je pas de commutateurs).

Alors, voici mon 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 );

Et au lieu d'un fichier xhtml je reçois une sortie comme ceci:

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

Il est juste la première partie de la sortie, mais je ne voulais pas copier tout le texte ici.

Tant le fichier xsl et dita fichier concept est de DITA Open Toolkit.

Toutes les idées ce qui ne va pas?

Était-ce utile?

La solution

Enfin, mon problème est résolu. Le tools.xml avait une référence externe dtd

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

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

Wich n'a pas été chargé par le DOMDocument par défaut, et qui a causé tous les problèmes. Si vous avez le même problème, vous devez utiliser l'option LIBXML_DTDATTR comme ceci:

$f = 'DITA-OT1.5.1/samples/concepts/tools.xml';
$XML = new DOMDocument();
$XML->load( $f,LIBXML_DTDATTR);
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top