致命错误! XSL 转换期间

发布于 2024-12-10 20:03:20 字数 1765 浏览 0 评论 0原文

我正在使用 DITA OT 将 XML 转换为 xhtml。我的 xsl 看起来像

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

现在如果我尝试使用 DITA OT jar cmd 针对我的 xml 执行此 xsl 以进行 xhtml 转换。

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

执行上述命令后,我收到以下错误。

[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

我很想找出为什么会发生这个错误。

谢谢。

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 " "> 
]>
<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">&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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

深陷 2024-12-17 20:03:20
this document contains a top-level text node

您能给我们展示一下 XSLT 样式表的结尾吗?最后的 之后是否有一些文本?那就会导致这个错误。

更新

正如 Dimitre 指出的那样, 开始/结束标记不平衡,因此除非您只显示 XSLT 的一部分,否则必须修复该问题。

不过,我同意 @Tim C 的观点,即您可能根本不希望在 XSLT 中使用 DOCTYPE 声明。您并不是在尝试使用样式表中的   实体,您只是在尝试发出一个实体。因此,如果您从样式表中删除 DOCTYPE 语句,您不会丢失任何内容。

此外,与@Tim相反,DOCTYPE不需要在输出HTML中声明nbsp实体,因为它已经在HTML中预定义了。

最后,在 HTML 中输出不间断空格的方法上,我与 @Tim 有所不同。禁用输出转义几乎总是错误的方法,这是由于缺乏对解析和序列化工作原理的理解。在 XSLT 中输出不间断空格字符的最简单方法是直接使用数字实体:

<div class="headerSeparator"> </div>

这将输出不间断空格。

“但是,”你说,“我希望它输出  !”

这可能会发生;当output-method =“html”时,序列化可以使用HTML内置的字符实体来表达这样的字符。或者序列化可以使用   或直接嵌入不间断空格字符。所有都是合法的 HTML,并且都是等效的。那么,您面临的问题是,为什么您希望将其序列化为   而不是其他等效项?

如果我误解了您想要执行的操作,请进一步解释您希望   出现的位置,以及为什么该特定形式很重要。

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   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"> </div>

This will output a non-breaking space.

"But," you say, "I want it to output  !"

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   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   as opposed to some other equivalent?

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

青柠芒果 2024-12-17 20:03:20

这可能是由于页面顶部的 DOCTYPE 声明所致。这也可能是错误所引用的顶级文本节点。

DOCTYPE 是您希望出现在您正在创建的 html 中的内容吗?如果是这样,可能应该将其从原来的位置删除,并在您的第一个模板中执行以下操作:

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

然后,当转换 XSLT 时,它将输出以下内容

<!DOCTYPE some_name [  <!ENTITY nbsp " ">  ]> 
<html>

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 " ">  ]> 
   ]]>
   </xsl:text>

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

<!DOCTYPE some_name [  <!ENTITY nbsp " ">  ]> 
<html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文