2014-06-13 68 views
-1

對於我們想構建的表格,我有以下xml格式,可以在結構上循環播放。但是我無法弄清楚爲什麼xsl-fo轉換爲PDF。從xml創建xsl-fo表格

<table> 
     <thead> 
      <tcell>data</tcell> 
      <tcell>data</tcell> 
      <tcell>data</tcell> 
     </thead> 
     <trow><tcell>data</tcell><tcell>data</tcell><tcell>data</tcell></trow> 
     <trow><tcell>data</tcell><tcell>data</tcell><tcell>data</tcell></trow> 
     <trow><tcell>data</tcell><tcell>data</tcell><tcell>data</tcell></trow> 
     <trow><tcell>data</tcell><tcell>data</tcell><tcell>data</tcell></trow> 
</table> 

回答

1

你沒有太多的問題(只是一些模糊的要求),但這至少應該讓你開始。

XML輸入

<table> 
    <thead> 
     <tcell>data</tcell> 
     <tcell>data</tcell> 
     <tcell>data</tcell> 
    </thead> 
    <trow><tcell>data</tcell><tcell>data</tcell><tcell>data</tcell></trow> 
    <trow><tcell>data</tcell><tcell>data</tcell><tcell>data</tcell></trow> 
    <trow><tcell>data</tcell><tcell>data</tcell><tcell>data</tcell></trow> 
    <trow><tcell>data</tcell><tcell>data</tcell><tcell>data</tcell></trow> 
</table> 

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="/"> 
     <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="table"> 
     <fo:table> 
      <xsl:apply-templates select="thead"/> 
      <fo:table-body> 
       <xsl:apply-templates select="trow"/> 
      </fo:table-body> 
     </fo:table> 
    </xsl:template> 

    <xsl:attribute-set name="trow"> 
     <xsl:attribute name="border">solid</xsl:attribute> 
     <xsl:attribute name="padding-left">1em</xsl:attribute> 
     <xsl:attribute name="padding-right">1em</xsl:attribute> 
    </xsl:attribute-set> 

    <xsl:template match="thead"> 
     <fo:table-header> 
      <fo:table-row background-color="#FFDEAD" text-align="center"> 
       <xsl:apply-templates/> 
      </fo:table-row> 
     </fo:table-header> 
    </xsl:template> 

    <xsl:template match="tcell"> 
     <fo:table-cell xsl:use-attribute-sets="trow"> 
      <fo:block><xsl:value-of select="."/></fo:block> 
     </fo:table-cell> 
    </xsl:template> 

    <xsl:template match="trow"> 
     <fo:table-row> 
      <xsl:apply-templates/> 
     </fo:table-row> 
    </xsl:template> 

</xsl:stylesheet> 

XSL-FO輸出(XSLT處理器用於:撒克遜-HE)

<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:table> 
      <fo:table-header> 
       <fo:table-row background-color="#FFDEAD" text-align="center"> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
       </fo:table-row> 
      </fo:table-header> 
      <fo:table-body> 
       <fo:table-row> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
       </fo:table-row> 
       <fo:table-row> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
       </fo:table-row> 
       <fo:table-row> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
       </fo:table-row> 
       <fo:table-row> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
        <fo:table-cell border="solid" padding-left="1em" padding-right="1em"> 
        <fo:block>data</fo:block> 
        </fo:table-cell> 
       </fo:table-row> 
      </fo:table-body> 
     </fo:table> 
     </fo:flow> 
    </fo:page-sequence> 
</fo:root> 

渲染PDF(使用XSL-FO處理器:Apache的FOP)

enter image description here

+0

由於這是我需要的。對於模糊的問題抱歉,但它遲到了,我想有人會理解這個問題。 – dutchlab