xsltproc:docbook 的文档类型

xsltproc: doctype for docbook

我有一个生成 DocBook XML 的 XSLT 样式 sheet。我使用 xsl:output 为 docbook

生成 DOCTYPE 声明
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" version="1.0"
              doctype-public="-//OASIS//DTD DocBook XML V4.5//EN"
             encoding="utf-8"
             indent="no" />

生成的 XML 文件有一个额外的空字符串,所以 xmllint 抱怨:

/path/docbk.xml:2: parser error : Content error in the external subset
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" ""><book>
^

这是 xsltproc 还是 XSLT 样式的问题sheet?

SGML 允许仅具有 PUBLIC 标识符的 DOCTYPE,但 XML 需要 系统标识符 - 您可以单独使用系统 ID,也可以使用public ID 和一个系统 ID,但不仅仅是 public 一个。 The docbook guide 建议

<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
               "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">

对应于

<xsl:output method="xml" version="1.0"
            doctype-public="-//OASIS//DTD DocBook XML V4.5//EN"
            doctype-system="http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
            encoding="utf-8"
            indent="no" />

事实上,xsltproc确实这里有一个错误,但不是你想的那个。来自 the spec for xsl:output:

If the doctype-system attribute is specified, the xml output method should output a document type declaration immediately before the first element. The name following <!DOCTYPE should be the name of the first element. If doctype-public attribute is also specified, then the xml output method should output PUBLIC followed by the public identifier and then the system identifier; otherwise, it should output SYSTEM followed by the system identifier. The internal subset should be empty. The doctype-public attribute should be ignored unless the doctype-system attribute is specified.

(我的粗体)