XQuery/安裝 XSL-FO 模組
您可能需要與 eXist 系統管理員合作,首先在您的系統上啟用 XSL-FO XQuery 模組,以便這些示例能夠執行。您可以使用以下步驟完成此操作。
編輯 $EXIST_HOME 目錄下的 conf.xml 檔案。您必須取消 xslfo 模組的註釋。
<module class="org.exist.xquery.modules.xslfo.XSLFOModule" uri="http://exist-db.org/xquery/xslfo" />
如果您的 eXist 不是從原始碼構建的,那麼 fo 模組和支援的 fop.jar 檔案也必須包含在所有生產系統中的 exist-modules.jar 檔案中。這可以透過下載 eXist 原始碼並更改 build.properties 檔案設定來完成。有關詳細資訊,請參閱 eXist 構建說明
$EXIST_HOME lib/extensions/build.properties 或 $EXIST_HOME extensions/build.properties
# XSL FO transformations (Uses Apache FOP) include.module.xslfo = true
如果您執行的是 eXist 1.4 版本,則引用的 Apache FOP 版本可能不再可用。如果您的 build-properties 中包含以下類似的程式碼行
include.module.xslfo.url = http://apache.cs.uu.nl/dist/xmlgraphics/fop/binaries/fop-0.95-bin.zip
您會發現 Apache 專案已經刪除了舊的二進位制檔案(並不總是最佳實踐)。
這是應該替換的新的程式碼行。
include.module.xslfo.url = http://apache.cs.uu.nl/dist/xmlgraphics/fop/binaries/fop-1.0-bin.zip
此外,將 $EXIST_HOME extensions/modules/build.xml 中對已棄用版本的引用更改為指向較新版本。例如
<!-- Apache FOP -->
<get src="${include.module.xslfo.url}" dest="fop-1.0-bin.zip" verbose="true" usetimestamp="true" />
<unzip src="fop-1.0-bin.zip" dest="${top.dir}/${lib.user}">
<patternset>
<include name="fop-1.0/build/fop.jar"/>
<include name="fop-1.0/lib/batik-all-*.jar"/>
<include name="fop-1.0/lib/xmlgraphics-commons-*.jar"/>
<include name="fop-1.0/lib/avalon-*.jar"/>
</patternset>
<mapper type="flatten"/>
</unzip>
<delete file="fop-1.0-bin.zip"/>
下次您執行構建時,這將從 Apache 網站下載 Apache FOP jar 檔案。
cd $EXIST_HOME/extensions/modules ant -version ant prepare-libs-xslfo
構建日誌示例
prepare-libs-xslfo:
[echo] Load: true
[echo] ------------------------------------------------------
[echo] Downloading libraries required by the xsl-fo module
[echo] ------------------------------------------------------
[get] Getting: http://apache.cs.uu.nl/dist/xmlgraphics/fop/binaries/fop-1.0-bin.zip
[get] To: C:\ws\eXist-1.4dev\extensions\modules\fop-1.0-bin.zip
[get] ....................................................
[get] last modified = Thu Jul 31 09:47:44 CDT 2008
[unzip] Expanding: C:\workspace\exist\extensions\modules\fop-1.0-bin.zip in to C:\workspace\exist\lib\user
請注意,除了 fop 二進位制檔案外,FOP 處理器還需要以下 jar 檔案。
$EXIST-HOME/lib/user/xmlgraphics-commons-1.3.1.jar
在 UNIX 上
$ sudo cp -v xmlgraphics-commons-1.4.jar $EXIST_HOME/lib/user `xmlgraphics-commons-1.4.jar' -> `/usr/local/exist/lib/user/xmlgraphics-commons-1.4.jar'
這可以從 Apache XML Graphics Commons Distribution Mirror 下載
將 $EXIST-HOME/lib/user/fop.jar 和新的 $EXIST-HOME/lib/extensions/exist-modules.jar 中的 jar 檔案複製到您的生產系統中。請注意,您應該確保源系統和目標系統是相同版本。
如果要使用 fop 對文字進行斷字,請將 fop-hyphen.jar 放入 $EXIST-HOME/lib/user/ 中,並重新啟動 eXist。如果在您的 fo 或 xsl 檔案中,將 hyphenate 屬性設定為 true,那麼 fo:blocks 將會斷字,如果您添加了 language 屬性到 fo:page-sequence 中。許多語言的斷字模式可以在這裡找到:http://sourceforge.net/projects/offo/
請注意,您的 exist-modules.jar 檔案隨後可以放在沒有原始碼的系統上。目前沒有不下載原始碼的情況下使用 FOP 的方法。另外請注意,您可以透過執行以下命令來驗證您的 exist-modules.jar 檔案中是否包含 XSLFO 類。
現在,您可以檢查 jar 檔案是否已正確安裝在使用者庫目錄中
$ ls -l $EXIST_HOME/lib/user/*.jar
這將返回
total 7480 -rwxrwxrwx 1 root root 56290 Nov 3 2009 activation-1.1.1.jar -rw-rw-r-- 1 ec2-user ec2-user 3318083 Jul 12 2010 batik-all-1.7.jar -rw-rw-r-- 1 ec2-user ec2-user 3079811 Jul 12 2010 fop.jar -rwxrwxrwx 1 root root 434812 Nov 3 2009 mail-1.4.2.jar -rwxrwxrwx 1 root root 117470 Nov 3 2009 nekohtml-1.9.11.jar -rw-r--r-- 1 root root 569113 Nov 12 17:28 xmlgraphics-commons-1.4.jar
在 shell 中鍵入以下命令
$ ./build.{sh|bat} extension-modules
如果構建失敗,並出現以下錯誤
"$EXIST_HOME/build/classes" does not exist or is not a directory
,建立 classes 資料夾會有所幫助,之後構建將會成功。
mkdir $EXIST_HOME/build/classes
$ jar tf exist-extensions.jar
或者在 Windows 系統上,您可以將 jar 檔案的檔名更改為以 .zip 結尾,解壓縮並檢查 xslfo 類是否在 exist-modules 檔案中。