2012-02-25 83 views
6

我想对xsl-fo进行xslt转换,但我不确定我能做到这一点。我尝试将XML列表转换为xsl-fo列表。任何人都可以告诉我在哪里可以找到我长时间使用谷歌搜索是没有很多这样的例子。我的XML就是这样。Xslt到xsl-fo转换

<p>TEXT</p> 
<ul> 
    <li>Item1</li> 
    <li>Item2</li> 
</ul> 
<p>ANOTHERTEXT</p> 

我尝试使用的模板,这种转变,但是我的模板不工作得到XSL-FO可有人告诉我,如果模板在这一转变的工作。如果他们工作可以让我看到一个例子,我找不到任何人。我objetive是得到一个PDF丝毫FOP

感谢


这是我的XML文档的一部分,我recived在HTML源的某些部分,并更改HTML到XML现在我尝试转换XML(白衣一列表)转换为XSLT的XSL-FO。我的问题是,我不能模仿这种转变。我的最终目标是得到一个pdf惠普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> 

我测试您的解决方案感谢所有

+1

HTML不具有100%的翻译XSL-FO。 – driis 2012-02-25 18:30:39

+0

什么是确切的预期结果?请编辑问题并提供。 XSLT专家很少也是xsl-fo-cognizant。 – 2012-02-25 18:47:12

回答

6

如果遇到与你的模板不工作的问题,这可能是一个命名空间的问题。您应该使用更精确的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>&#x02022;</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防输出

enter image description here

0

首先,确保你有一个XHTML文件(无<等等)。然后应用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> 

检查http://www.w3schools.com/xslfo/default.asp为XSLFO语法。

查看http://xmlgraphics.apache.org/fop/trunk/running.html有关运行fop的信息; 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) 

(类似命令行)