Question

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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top