我想使用docbook XSL樣式表來呈現文檔的各個部分,而不用轉換整個東西。做一個Docbook元素樹分支的XSL轉換
複雜情況是這些零件中有一些具有<footnoteref>
元素,其linkend
屬性不在同一個塊內。換句話說,我想處理一個包含<footnoteref>
但不包含它們引用的元素的樹的分支。
我試圖執行此使用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>
到<footnote>
轉換。我期待已經發生的事情。但希望我錯過了某個地方的開關。
編輯
感謝@尤卡的回答,我已經想通了,我可以通過rootid參數告訴XSLT處理器僅僅渲染ID。但是,它的確如此,如果文檔被渲染爲一個單獨的HTML頁面,那麼產生的輸出只會引用具有相同片段的腳註。 EG
>>> xsl_url_html = 'http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl'
>>> from lxml import etree
>>> consume_result = etree.XSLT(etree.parse(xsl_url_xhtml))(
etree.parse(my_xml_file), rootid=etree.XSLT.strparam("command_consume"))
>>> etree.tostring(consume_result).split('\n')
['<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
'<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=ASCII" /><title></title><meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /></head><body><dt><a id="command_consume"></a><span class="term">',
' <div class="cmdsynopsis"><p><code class="command">consume</code> {<em class="replaceable"><code>STATE</code></em>}</p></div>',
' </span></dt><dd><p>',
' <sup>[<a href="#ftn.since_0_15" class="footnoteref">2</a>]</sup>',
' Sets consume state to <code class="varname">STATE</code>,',
' <code class="varname">STATE</code> should be 0 or 1.',
'\t When consume is activated, each song played is removed from playlist.',
' </p></dd></body></html>']
也許有要被顯示在同一頁上,這將導致腳註的另一參數,優選從1編號?我想它可能在this list某處。當我有更多時間時,我會經歷它。
聽起來很有用..但儘管我想要處理的部分包含標籤,如'',我發現將'rootid =「command_rescan」'傳遞給Python lxml.etree.XSLT對象的調用不會工作。 XSLT對象是從[http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl]的分析中初始化的。任何想法可能是錯的?我基本上是從'lxml import etree' etree.XSLT(etree.parse(that_url))(etree.parse(my_xml_file),rootid =「command_rescan」)'。沒有傳遞'rootid'參數,它給了我相同的結果。 –
intuited
2010-07-29 22:19:15
哈哈!沒關係,我意識到我需要通過'etree.XSLT.strparam(「command_rescan」)''來傳遞它作爲'rootid'關鍵字參數的值。 – intuited 2010-07-29 22:23:42
除了它實際上並沒有在渲染頁面的底部寫一個腳註的副本,它只是引用它與所使用的數字,如果你正在渲染整個文檔。 – intuited 2010-07-29 22:31:36