1

さまざまな数の列を持つ xsl fo テーブルを作成しています。アプリケーションは Apache FOP を使用して、変換されたドキュメントを表示します。列の数が少ない場合、すべてが正常に表示されます (つまり、セルの内容は中央に配置され、全体が表示されますが、一部の列はテキストが折り返されて 2 行を占めることになります)。ただし、一部のテーブルには 12 列を超える列があり、ここで問題が発生します。列ヘッダー セルでは、列の名前がセルの右側に複数行にわたって表示されます。言葉が折り重なっているように見えますが、最後の 2 文字も途切れているように見えます。テキストが隣接セルに漏れていません。

この場合の入力 xml ファイルは次のとおりです。簡潔にするために、1 行がテーブル ヘッダーで、1 行が本文です。その部分が適切に表示されるため、xsl ドキュメントで参照されているグラフ要素は含めませんでした。

<exports>
   <export>
     <table>
        <tblRow>
            <hdrCell>Month</hdrCell>
            <hdrCell>Allow Amt PEPM Med</hdrCell>
            <hdrCell>Allow Amt PEPM Rx</hdrCell>
            <hdrCell>Allow Amt PEPM Med and Rx</hdrCell>
            <hdrCell>Allow Amt PMPM Med</hdrCell>
            <hdrCell>Allow Amt PMPM Rx</hdrCell>
            <hdrCell>Allow Amt PMPM Med and Rx</hdrCell>
            <hdrCell>Employees Avg Med or Rx</hdrCell>
            <hdrCell>Members Avg Med or Rx</hdrCell>
            <hdrCell>Net Pay PEPM Med</hdrCell>
            <hdrCell>Net Pay PEPM Rx</hdrCell>
            <hdrCell>Net Pay PEPM Med and Rx</hdrCell>
            <hdrCell>Net Pay PMPM Med</hdrCell>
            <hdrCell>Net Pay PMPM Rx</hdrCell>
            <hdrCell>Net Pay PMPM Med and Rx</hdrCell>
        </tblRow>
        <tblRow>
            <tblCell>Jan 2010</tblCell>
            <tblCell>11</tblCell>
            <tblCell>202</tblCell>
            <tblCell>213</tblCell>
            <tblCell>26</tblCell>
            <tblCell>30</tblCell>
            <tblCell>56</tblCell>
            <tblCell>56</tblCell>
            <tblCell>44</tblCell>
            <tblCell>11</tblCell>
            <tblCell>22</tblCell>
            <tblCell>33</tblCell>
            <tblCell>12</tblCell>
            <tblCell>12</tblCell>
            <tblCell>24</tblCell>
            <tblCell>1</tblCell>
        </tblRow>

    </table>
</export>

そして、これが入力ファイルを xsl fo に変換する xsl ファイルです。私はxslが初めてです。

<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 method="xml" indent="yes"/>
   <xsl:template match="/">
   <fo:root>
         <fo:layout-master-set>
             <fo:simple-page-master master-name="exportPage">
                 <fo:region-body />
             </fo:simple-page-master>
         </fo:layout-master-set>
         <fo:page-sequence master-reference="exportPage">
             <fo:flow flow-name="xsl-region-body">
                  <fo:block id="chartBlock">
                          <!-- THIS PART WORKS FINE -->
                  </fo:block>
                 <!-- THE PROBLEM PART -->
                 <fo:block id="tableBlock" margin="0.25in">
                        <xsl:apply-templates select="exports/export/table"/>
                 </fo:block>
             </fo:flow>
        </fo:page-sequence>
    </fo:root>

</xsl:template>
    <!-- Creates the table -->
    <xsl:template match="table">
        <fo:table table-layout="fixed" width="100%" >
            <fo:table-header>
                <fo:table-row>
                    <xsl:apply-templates select="tblRow[position() = 1]"/>
                </fo:table-row>
            </fo:table-header>
            <fo:table-body>
                <xsl:apply-templates select="tblRow[position() > 1]"/>
            </fo:table-body>
        </fo:table>
    </xsl:template>

    <xsl:template match="hdrCell">
        <fo:table-cell background-color="#666" border-right-style="solid" border-right-width="1px" border-right-color="white" empty-cells="show">
            <fo:block color="white" font-family="arial, helvetica, sans-serif" font-size="xx-small"><xsl:value-of select="."/></fo:block>
        </fo:table-cell>
    </xsl:template>

    <xsl:template match="tblCell">
   <fo:table-cell border-bottom-style="solid" border-bottom-width="1px"
   border-bottom-color="#E3E3E3">
   <fo:block color="#7E7E7E" font-family="arial, helvetica, sans-serif" font-                                                size="xx-small"><xsl:value-of select="."/></fo:block>
        </fo:table-cell>
    </xsl:template >

    <xsl:template match="tblRow[position() > 1]">
        <fo:table-row>
            <xsl:apply-templates />
        </fo:table-row>
    </xsl:template>

 </xsl:stylesheet>

テーブルセルのブロック要素ごとに右パディングプロパティを設定しようとしましたが、テキストが左にシフトして無駄になることを期待しています。テーブルセルの子である各ブロック要素の「幅」プロパティを調整しようとしました。私は一般的にxslに慣れていないので、どのように進めればよいかわかりません。特定の幅の要素を指定すると便利ですか? テーブルの全幅が PDF に表示され、このごちゃごちゃした、切り捨てられたセルの内容がないことを確認するにはどうすればよいですか? また、指定されていない場合、すべての単位は「px」です。

前もって感謝します、

ブラント

4

1 に答える 1

2

回答: 周囲のブロックから margin="0.25in" を削除すると、期待どおりの結果が得られます (もちろん、そのブロックのマージンは除きます)。明確にするために、これを変更します。

<fo:block id="tableBlock" margin="0.25in">
      <xsl:apply-templates select="exports/export/table"/>
</fo:block>

margin="0.25in" を削除します。

注: これは、別のフォーマッタから得られる結果ではありません。元のファイルで RenderX を使用したところ、期待どおりの正しい結果が得られました。私はFOPを使用し、間違った結果を得ましたが、そのインデントを削除しました(これは明らかに、テーブルセルの1つの次元のみに不適切に継承されています)。

追加の注意: サンプルには 15 個のヘッダー セルと 16 個のセルがあります。

于 2013-10-07T02:25:27.283 に答える