[英]Xslt to xsl-fo transformation
我想對xsl-fo進行xslt轉換,但我不確定我能做到這一點。 我嘗試將XML列表轉換為xsl-fo列表。 任何人都可以告訴我在哪里可以尋找我谷歌搜索很長一段時間沒有很多這方面的例子。 我的XML是這樣的。
<p>TEXT</p>
<ul>
<li>Item1</li>
<li>Item2</li>
</ul>
<p>ANOTHERTEXT</p>
我嘗試使用模板進行此轉換,但我的模板無法獲得xsl-fo任何人都可以告訴我模板是否適用於此轉換。 如果他們工作可以告訴我一個例子,我找不到任何人。 我的目標是得到一個pdf whit fop
謝謝
這是我的XML文檔的一部分我在HTML中收集了源代碼的一些部分,我將HTML更改為XML,現在我嘗試將XML(在列表中)轉換為XSL-FO中的XSLT。 我的問題是我無法為這種轉變提供模板。 我最后的目標是獲得一個pdf whit FOP。
謝謝
UPDATE
這是我的XML:
<Memoria>
<name>TITLE</name>
<Index>INDEX 2010</Index>
<Seccion>
<name>INFORMATION</name>
<Contenido>
<p>TEXT</p>
<ul>
<li>ITEM1</li>
<li>ITEM2</li>
</ul>
<p>ANOTHER</p>
</Contenido>
</Seccion>
</Memoria>
我正在測試你的解決方案謝謝大家
如果您的模板出現問題,則可能是命名空間問題。 您應該使用更准確的XML示例更新問題。
這是一個例子。
XML輸入 (固定為格式良好)
<root>
<p>TEXT</p>
<ul>
<li>Item1</li>
<li>Item2</li>
</ul>
<p>ANOTHERTEXT</p>
</root>
XSLT 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/root">
<fo:root>
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
<fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<xsl:apply-templates/>
</fo:flow>
</fo:page-sequence>
</fo:root>
</xsl:template>
<xsl:template match="p">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<xsl:template match="ul">
<fo:list-block padding="4pt">
<xsl:apply-templates/>
</fo:list-block>
</xsl:template>
<xsl:template match="li">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>•</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</xsl:template>
</xsl:stylesheet>
XSL-FO輸出
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
<fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="my-page">
<fo:flow flow-name="xsl-region-body">
<fo:block>TEXT</fo:block>
<fo:list-block padding="4pt">
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>•</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>Item1</fo:block>
</fo:list-item-body>
</fo:list-item>
<fo:list-item>
<fo:list-item-label end-indent="label-end()">
<fo:block>•</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent="body-start()">
<fo:block>Item2</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
<fo:block>ANOTHERTEXT</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
Apache FOP輸出
首先,確保你有一個xhtml文件(沒有<br>等)。 然后應用xslt轉換來創建fo文件,然后將其提供給fop並顯示pdf。
xslt fo風格的片段:
<xsl:template match="html:body">
<fo:page-sequence master-reference="all-pages">
<fo:title>
<xsl:value-of select="/html:html/html:head/html:title"/>
</fo:title>
<fo:static-content flow-name="page-header">
<fo:block font-weight="bold" font-size="16pt" space-before.conditionality="retain" xsl:use-attribute-sets="page-header"><!-- space-before="{$page-header-margin}" -->
<xsl:if test="$title-print-in-header = 'true'">
<xsl:value-of select="/html:html/html:head/html:title"/>
</xsl:if>
</fo:block>
</fo:static-content>
</fo:page-sequence>
</xsl:template>
有關xslfo語法,請訪問http://www.w3schools.com/xslfo/default.asp 。
有關運行fop的信息,請參見http://xmlgraphics.apache.org/fop/trunk/running.html ; fop.jar的下載必須在附近。
從vba運行,例如如下:
Set shell = CreateObject("WScript.Shell")
cmd = "java -Dfop.home=" & baseDir & " -cp " & baseDir & "build\fop.jar org.apache.fop.cli.Main -fo " & foName & " -pdf " & pdfName
Call shell.Run(cmd, vbWindowFrame, True)
(類似於命令行)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.