对Docbook elemen的分支执行XSL转换

2024-04-29 07:10:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我希望使用docbook XSL样式表来呈现文档的各个部分,而不需要转换整个内容。在

复杂的是其中一些部分有<footnoteref>元素,它们的linkend属性不在同一个块中。换句话说,我想处理树的一个分支,它包含<footnoteref>s,但不包括它们引用的<footnote>元素。在

我尝试使用Python lxml包执行此操作时,出现了以下错误消息:

XSLTApplyError                            Traceback (most recent call last)

/var/www/mpd/<ipython console> in <module>()

/var/www/mpd/<ipython console> in <genexpr>((elt,))

/usr/lib/python2.6/dist-packages/lxml/etree.so in lxml.etree.XSLT.__call__ (src/lxml/lxml.etree.c:109204)()

XSLTApplyError: Internal error in xsltKeyFunction(): Could not get the document info of a context doc.

这是对etree.XSLT(etree.parse('docbook.xsl'))(some_element)的响应。在

我使用的是普通的xhtml样式表。不过,我并不认为我使用的是哪个样式表。在

有没有一种受支持的方法?或者,例如,在执行此呈现之前,我是否应该对文档应用XSLT转换,将<footnoteref>元素更改为<footnote>元素?但是这样做就行不通了,因为这样会有多个具有相同ID的<footnote>标记,如果结果树中没有包含<footnote>标记,则只需对<footnoteref>到{}转换。我希望已经发生了。但希望我错过了某个地方的开关。在

编辑

多亏了@Jukka的回答,我发现我可以传递rootid参数来告诉XSLT处理器只呈现该ID。但是,它做得太忠实了,生成的输出只是引用了脚注,并且带有相同的片段,如果文档被呈现为一个HTML页面,这将非常有用。例如

^{pr2}$

也许还有另一个参数会导致脚注显示在同一页上,最好从1开始编号?我想它可能在this list的某个地方。等我有时间再看一遍。在


Tags: in文档元素varwwwcall样式表lxml
1条回答
网友
1楼 · 发布于 2024-04-29 07:10:22

您不必尝试将DocBook XSL样式表应用于单个元素,而是可以将其应用于整个文档,但要使用^{}参数指定要转换的文档部分。在

参考文件:

The entire document will be loaded and parsed, but formatting will begin at the element identified, rather than at the root. For example, this allows you to process only chapter 4 of a book.

Because the entire document is available to the processor, automatic numbering, cross references, and other dependencies are correctly resolved.

相关问题 更多 >