从xml创建xsl fo表

从xml创建xsl fo表,xml,pdf,xslt,html-table,xsl-fo,Xml,Pdf,Xslt,Html Table,Xsl Fo,对于我们要构建的表,我有以下xml格式,它可以很好地按照结构上的循环方式工作。但是,我不知道如何将xsl fo转换为PDF <table> <thead> <tcell>data</tcell> <tcell>data</tcell> <tcell>data</tcell> </thead>

对于我们要构建的表,我有以下xml格式,它可以很好地按照结构上的循环方式工作。但是,我不知道如何将xsl fo转换为PDF

 <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>

数据
数据
数据
数据
数据
数据
数据

您没有太多问题(只是一些模糊的需求),但这至少可以让您开始

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>

数据
数据
数据
数据
数据
数据
数据
XSLT1.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>

固体
1em
1em
XSL-FO输出(使用的XSLT处理器:Saxon HE)


数据
数据
数据
数据
数据
数据
数据
数据
数据
数据
数据
数据
数据
数据
数据
呈现的PDF(使用的XSL-FO处理器:Apache FOP)


谢谢,这正是我需要的。很抱歉这个模糊的问题,但是时间已经晚了,我想有人会理解这个问题的。
<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>