跳轉到內容

XQuery/DocBook 到 PDF

來自華夏公益教科書,開放的書籍,開放的世界

您希望將您的 DocBook 5 檔案轉換為 PDF 格式。PDF 是一種標準化的頁面佈局格式,允許您使用標準列印書籍。

我們將建立一個 XQuery 模組,其中包含針對 DocBook 每個主要元素的一個主要 TypeSwitch 語句。這將建立一個 XSL-FO 檔案,然後可以使用 Apache-FO 1.0 處理器 直接將其轉換為 PDF。

這將完全使用 XQuery 完成。不需要 XSLT。

示例輸入文件

[編輯 | 編輯原始碼]

我們將從一個簡單的 DocBook 5 文件開始。該文件使用 DocBook 名稱空間幷包含 xlink 名稱空間。文件的非常小的示例可能具有以下結構

<book xmlns="http://docbook.org/ns/docbook"
    xmlns:xlink="http://www.w3.org/1999/xlink" version="5.0">
    <info>
        <title>Converting DocBook to PDF using XQuery</title>
        <author>
            <orgname>Kelly McCreary &amp; Associates</orgname>
            <address>
                <city>Minneapolis</city>
                <country>USA</country>
            </address>
            <email>user@example.com</email>
        </author>
    </info>
    <part>
        <title>Introduction</title>
        <subtitle>Why DocBook and PDF</subtitle>
        <chapter>
            <title>Introduction to DocBook</title>
            <subtitle>Getting Started with DocBook Version</subtitle>
            <sect1>
                <title>Page Layout vs. Scrolling HTML</title>
                <subtitle>Why PDF is Used For Printing</subtitle>
                <para>Printing and pagination will still be important till ePub becomes standardized.</para>
            </sect1>
        </chapter>
        <chapter>
            <title>XQuery Typeswitch Transforms</title>
            <subtitle>How To Get Comfortable with Recursive Programs</subtitle>
            <sect1>
                <title>Why XQuery Can Replace XSLT</title>
                <subtitle>One language for the server</subtitle>
                <para>Text</para>
            </sect1>
            <sect1>
                <title>XSL-FO</title>
                <subtitle>A language for paginated layout</subtitle>
                <para>Text</para>
            </sect1>
        </chapter>
    </part>
</book>
華夏公益教科書