2011-04-13 21 views
0

私はfopファイル(FOPファクトリを使用して、javax.xml.transform.TransformerFactoryを使用)に変換するxsl-xmlファイルを持っていますので、最終的にPDFに変換できます。これまでは単純なデータだけを入力しなければならなかったので、xslでは次のようなコードを書いていました。xsl -xml foファイル - xmlにテーブルデータを入力

<xsl:template match="p"> 
    <fo:block> 
     <xsl:apply-templates/> 
    </fo:block> 
</xsl:template> 
<xsl:template match="center"> 
    <fo:block alignment-adjust="middle"> 
     <xsl:apply-templates/> 
    </fo:block> 
</xsl:template> 
<xsl:template match="b"> 
    <fo:inline font-weight="bold"> 
     <xsl:apply-templates/> 
    </fo:inline> 
</xsl:template> 

などと書いています。
そして、私はFOPファイルに変換したとき、私は得る:

<fo:block text-align="center" font-weight="bold" 
      text-decoration="underline" 
      padding-after="10">Sales Contract for <fo:inline font-weight="bold" 
      color="red">Mobile 100</fo:inline> 
</fo:block> 

等...

は、今私は、私は、データを持つテーブルを表示する必要がある状況があります。 XMLでテーブルテンプレートを定義するにはどうすればよいですか?XMLに何を追加する必要がありますか?

+0

xslのテキストが上の質問にはありません。ここでは、 RBY

+0

:http://www.w3.org/TR/xsl /#d0e11404。 'fo:block'と' fo:inline'要素だけを出力するのではなく、 'fo:table'、' fo:table-column'などを使わなければなりません。あなたは何に問題がありますか? – mzjn

答えて

0

私はあなたが望むものを理解していません...しかし、すべてのケースで私はテーブルの例を書いています。

<table ENABLE="true" id="" title=""> 
    <tgroup ENABLE="true" cols=""> 
     <tbody ENABLE="true"> 
     <row ENABLE="true"> 
      <entry ENABLE="true" align="0 left"> 
      <text ENABLE="true"> 
       <DATA ENC="enc" LABEL="label">First row, first column (entry)</DATA> 
      </text> 
      </entry> 
      <entry ENABLE="true" align="0 left"> 
      <text ENABLE="true"> 
       <DATA ENC="enc" LABEL="label">First row, second column (entry)</DATA> 
      </text> 
      </entry> 
     </row> 
     <row ENABLE="true"> 
      <entry ENABLE="true" align="0 left"> 
      <text ENABLE="true"> 
       <DATA ENC="enc" LABEL="label">Second row, first column (entry)</DATA> 
      </text> 
      </entry> 
      <entry ENABLE="true" align="0 left"> 
      <text ENABLE="true"> 
       <DATA ENC="enc" LABEL="label">Second row, second column (entry)</DATA> 
      </text> 
      </entry> 
     </row> 
     </tbody> 
    </tgroup> 
    </table> 

XSL-FOがあり得る:

<xsl:template match="table"> 
     <fo:block> 
      <fo:inline font-size="10pt" font-weight="bold" clear="both" float="right"> 
       <xsl:text>Table&#x20;</xsl:text><xsl:if test="@id"><xsl:apply-templates select="@id"/></xsl:if><xsl:if test="@title"><xsl:text>&#x20;</xsl:text><xsl:apply-templates select="@title"/></xsl:if> 
      </fo:inline> 
     </fo:block> 
     <xsl:if test="descendant::*[self::row]"> 
      <fo:table margin-top="0.2in" border-top-color="#a0c0ff" border-top-width="0.01042in" border-bottom-style="solid" border-bottom-color="#a0c0ff" border-bottom-width="0.01042in" border-left-style="solid" border-left-color="#a0c0ff" border-left-width="0.01042in" border-right-style="solid" border-right-color="#a0c0ff" border-right-width="0.01042in" border-collapse="separate" background-color="#e9e9ff" color="black" display-align="center" text-align="left"> 
       <xsl:apply-templates select="child::*[self::thead or self::tbody or tfoot]" mode="calculate_columns"/>    
        <fo:table-body> 
           <xsl:apply-templates/> 
         </fo:table-body> 
        </fo:table> 
        <fo:block> 
         <fo:leader leader-pattern="space"/> 
        </fo:block> 
     </xsl:if> 
    </xsl:template>   

    <xsl:template match="row" mode="calculate_columns"> 
      <xsl:variable name="columns" select="count(entry)"/> 
      <xsl:variable name="table-width" select="ancestor::table[@width]"/> 
      <xsl:param name="maxwidth" select="7.30000"/> 
      <xsl:variable name="column-width"> 
      <xsl:value-of select="concat($table-width div $columns, 'cm')"/> 
      </xsl:variable> 
      <xsl:for-each select="entry"> 
       <xsl:variable name="column-number"> 
        <xsl:number level="multiple" count="entry" format="1" /> 
       </xsl:variable> 
       <fo:table-column column-number="{$column-number}" column-width="{$column-width}"/> 
      </xsl:for-each> 
    </xsl:template> 

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

    <xsl:template match="entry"> 
     <fo:table-cell border-top-style="solid" border-top-color="#a0c0ff" border-top-width="0.01042in" border-bottom-style="solid" border-bottom-color="#a0c0ff" border-bottom-width="0.01042in" border-left-style="solid" border-left-color="#a0c0ff" border-left-width="0.01042in" border-right-style="solid" border-right-color="#a0c0ff" border-right-width="0.01042in"> 
     <fo:block padding-top="1pt" padding-bottom="1pt"> 
     <fo:inline> 
      <xsl:apply-templates/> 
     </fo:inline> 
     </fo:block> 
     </fo:table-cell> 
    </xsl:template> 
あなたがタグ「行」は、テーブルの行を表し、タグ「エントリ」は列従うようにフォーマットされたテーブルを、あるとし