【发布时间】:2019-04-03 18:03:50
【问题描述】:
我们使用 DocBook XSLT 将 CALS 表转换为 HTML 以用于 Web 输出。我们的一些 CALS 表包含 HTML 标记,特别是列表。我不确定这是否正常,但我们的打印 (PDF) 格式化引擎 - 将 CALS 表作为输入 - 会处理它。
但是,当 CALS 表转换为 HTML 时,带有标签的列表标记将呈现为字符串,并且列表嵌套保留在跨度中(奇怪!)。
更新:我怀疑我在 DocBook XSLT 应用程序中一定做错了,该应用程序旨在转换表格,同时简单地从混合内容类型的文档中复制所有其他内容。这是一个可重现的示例:
CALS 输入:
<section>
<table>
<tgroup cols="1">
<colspec colname="col1"/>
<tbody>
<row>
<entry>
<ol list-style-type="lower-alpha" period-paren="paren">
<li>This is a nested list:<ol list-style-type="number" period-paren="paren">
<li>I'm a list item.</li>
<li>I'm another list item!</li>
</ol></li>
<li>Yet another nested list:<ol list-style-type="number" period-paren="paren">
<li>YALI</li>
<li>YAYALI</li>
</ol></li>
</ol>
</entry>
</row>
</tbody>
</tgroup>
</table>
</section>
XSLT:
<xsl:stylesheet version="2.0"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="docbook-xsl-1.75.2/xhtml/docbook.xsl"/>
<xsl:template match="/ | /*">
<xsl:apply-templates mode="initial"/>
</xsl:template>
<xsl:template match="table" mode="initial">
<xsl:apply-templates select="." mode="#default"/>
</xsl:template>
<xsl:template match="@*|node()" mode="initial">
<xsl:copy>
<xsl:apply-templates select="@*|node()" mode="#current"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
输出:
<section><div class="table" xmlns="http://www.w3.org/1999/xhtml">
<a id="n5dd3b973684deaa" xmlns:saxon="http://icl.com/saxon"></a><p class="title"><b></b></p>
<div class="table-contents">
<table border="1"><tbody><tr><td>
<span style="color: red"><ol>
<span style="color: red"><li>This is a nested list:<span style="color: red"><ol>
<span style="color: red"><li>I'm a list item.</li></span>
<span style="color: red"><li>I'm another list item!</li></span>
</ol></span></li></span>
<span style="color: red"><li>Yet another nested list:<span style="color: red"><ol>
<span style="color: red"><li>YALI</li></span>
<span style="color: red"><li>YAYALI</li></span>
</ol></span></li></span>
</ol></span>
</td></tr></tbody></table>
</div></div>
<br class="table-break" xmlns="http://www.w3.org/1999/xhtml"/>
</section>
【问题讨论】:
-
<td class="UNRECOGNIZED">似乎在暗示渲染器发现了一个它不准备查看的节点并将源代码转换为红色文本,以便在您查看渲染输出时帮助调试。保留嵌套一点也不奇怪。 -
如果没有看到生成此输出的 XSLT 代码,很难知道如何才能让这些节点“被识别”(我的直觉是“为它们编写模板”)。
-
@Tomalak 这些是样式表:github.com/docbook/xslt10-stylesheets/releases。因为它是一个如此大的库,所以我对试图覆盖它持谨慎态度,我希望有一种正式的方式来获得我想要的行为(因为这看起来很奇怪)。
-
除了了解基础知识(并且与 XSLT 本身相处得很好)之外,我对 docbook 没有太多经验,所以我的一般策略是确定代码库中创建的位置这个
class="UNRECOGNIZED"属性并向外工作以了解它出现的原因。 -
DocBook XML 文档或片段是否有命名空间?您的 sn-p 中没有显示任何内容。我尝试使用您的初始片段运行一个简单示例,但昨天在 oXygen 中添加了 docbook 命名空间,它确实给出了您显示的转义输出,但 oXygen 还指出 XSLT 处理器发出的几个警告和
xsl:message未知元素,如 @已遇到 987654328@ 或li。
标签: html xslt docbook-xsl