Question

I am using DITA OT for transforming the XML into xhtml. My xsl looks like

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE some_name [ 
<!ENTITY nbsp "&#160;"> 
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:saxon="http://icl.com/saxon" extension-element-prefixes="saxon">


 <xsl:import href="../map2xhtmtoc.xsl"/>
 <!--<xsl:import href="result-doc.xsl"/>-->
 <!--<xsl:import href="custom-ecollege-dita2xhtml.xsl"/>-->
 <xsl:output name="html" method="html" indent="yes" encoding="UTF-8"/>

 <!-- Define a newline character -->
 <xsl:variable name="newline">
  <xsl:text>
  </xsl:text>
 </xsl:variable>

 <xsl:template match="/">
    <html>
    <head>
      <body>
          <xsl:apply-templates select="myProduct"/>
      </body>
    </head>
    </html>
 </xsl:template>
 <!--other templates goes here-->
 <div class="floatRight"/>
 <div class="headerSeparator">
  <xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
 </div>
 </xsl:template>

 </xsl:stylesheet>

Now If I tried to execute this xsl against my xml for xhtml transformation using DITA OT jar cmd.

java -jar .\lib\dost.jar /i:samples/mycompany/myContent/myContent.ditamap /transtype:xhtml /xsl:xsl/mycompany/custom-map2xhtml.xsl

After executing the above command, I am getting the following error.

[xslt] D:\DITA-OT1.5.2\xsl\mycompany\custom-map2xhtm.xsl:21: Fatal Error! When 'standalone' or 'doctype-system' is specified, the document must be well-formed; but this document contains a top-level text node
[xslt] Failed to process null

Am breaking my head to find out why this error is occuring.

Thanks.

Was it helpful?

Solution

this document contains a top-level text node

Can you show us the end of the XSLT stylesheet? Is there some text after the final </xsl:stylesheet>? That would cause this error.

Update

As Dimitre pointed out, the <xsl:template> start/end tags are unbalanced, so unless you're only showing part of your XSLT, that has to be fixed.

However, I agree with @Tim C that you probably don't really want a DOCTYPE declaration at all in your XSLT. You're not trying to use the &nbsp; entity in the stylesheet, you're just trying to emit one. So if you removed the DOCTYPE statement from your stylesheet, you would lose nothing.

Moreover, contra @Tim, there is no need for a DOCTYPE to declare the nbsp entity in the output HTML, because it's already predefined in HTML.

Finally, I would differ with @Tim on the method for outputting a non-breaking space in the HTML. Disable-output-escaping is almost always the wrong approach, and is due to a lack of understanding of how parsing and serialization work. The easiest way to output a non-breaking space character in XSLT is to use a numeric entity directly:

<div class="headerSeparator">&#160;</div>

This will output a non-breaking space.

"But," you say, "I want it to output &nbsp;!"

That may happen; when output-method="html", serialization may use the character entities built in to HTML to express characters like this. Or the serialization could use &#160; or simply embed a non-breaking space character directly. All are legal HTML, and all are equivalent. The question for you, then, is why do you want it serialized as &nbsp; as opposed to some other equivalent?

If I've misunderstood what you're trying to do, please explain further, where you want &nbsp; to appear, and why that particular form matters.

OTHER TIPS

This may be because of the DOCTYPE declaration you have at the top of the page. This could be the top-level text node the error is referring too.

Is the DOCTYPE something you wish to appear in the html you are creating? If so, it should probably be removed from where it is, and in your first template, do the following:

<xsl:template match="/">
   <xsl:text disable-output-escaping = "yes"><![CDATA[
      <!DOCTYPE some_name [  <!ENTITY nbsp "&#160;">  ]> 
   ]]>
   </xsl:text>

Then, when the XSLT is transformed, it will output the following

<!DOCTYPE some_name [  <!ENTITY nbsp "&#160;">  ]> 
<html>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top