2011/05/24

ページによるヘッダ・フッタの切り替え (Switching the header / footer contents)

ヘッダとフッタをページに応じて切り替える、という要件は古くも新しい話題です。
US-OTNでも何度も話題に上がっていますが、そのほとんどにおいて最初のページと最後のページのヘッダおよびフッタの扱いが問題となっています。

BI Publisher ではヘッダおよびフッタ領域の区切りとして以下のタグを提供しています。
<?start:body?><?end body?>
<?start@last-page:body?><?end body?>
<?start@last-page-first:body?><?end body?>

しかし、これらだけでは、たとえば以下のような要件を満たすことはできません。
  • 最初のページ、中間のページ、および最後のページでヘッダ・フッタを切り替える
  • 内容が1ページに収まる場合には、最初のページのヘッダ最後のページのフッタを出力する

【具体例】
上記の要件の具体例を以下に示します。

先頭のページには文字列 First page header、および First page footer が出力されます。

Figure 1: page 1 of 3 (First page)


2番目の(中間の)ページには、文字列 Middle page header、および Middle page footer が出力されます。
Figure 2: page 2 of 3 (Middle page)

最後のページには文字列 Last page header、および Last page footer が表示されます。
Figure 3: page 3 of 3 (Last page)


また、このレポートが1ページに収まる場合の出力は以下の通りです。ヘッダには文字列 First page header を表示しつつ、フッタには Last page footer が出力されます。

Figure 4: Single page (The first page is the last page)

【xdofo:inline-total】
上記のような要件を満たすには、xdofo:inline-total オブジェクトを使用します。本来、このオブジェクトはページ間で数値の累計を受け渡す為のものですが、ヘッダおよびフッタの切り替えに使用することもできます。

xdofo:inline-total に定義されている表示条件(display-condition)は以下の通りです。
  • first
  • last
  • exceptfirst
  • exceptlast
  • everytime (デフォルト)


マニュアルは以下のURLにて参照できます。
http://download.oracle.com/docs/cd/E14571_01/bi.1111/e13881/T421739T481157.htm


テンプレートをこちらに用意しました。

構文を以下に説明します。

以下の設定は、最初のページのみに現れるヘッダを定義しています。
<xdofo:inline-total display-condition="first" name="vDummy">
First page header
</xdofo:inline-total>


以下の設定は、中間のページのヘッダを定義しています。 exceptfirstとexceptlastをネストすることで、中間のみの出力を実現します。
<xdofo:inline-total display-condition="exceptfirst" name="vDummy">
<xdofo:inline-total display-condition="exceptlast" name="vDummy">
Middle page header
</xdofo:inline-total>
</xdofo:inline-total>


以下の設定は、最後のページのヘッダを定義しています。exceptfirstをネストして定義することで、レポートが1ページのみの場合に非表示になります。
<xdofo:inline-total display-condition="last" name="vDummy">
<xdofo:inline-total display-condition="exceptfirst" name="vDummy">
last page header
</xdofo:inline-total>
</xdofo:inline-total>



以下の設定は、最初のページのフッタを定義しています。exceptlastをネストして定義することで、レポートが1ページのみの場合に非表示になります。
<xdofo:inline-total display-condition="first" name="vDummy">
<xdofo:inline-total display-condition="exceptlast" name="vDummy">
First page footer
</xdofo:inline-total>
</xdofo:inline-total>


以下の設定は、最後のページのフッタを定義しています。レポートが1ページのみの場合、最初のページが最後のページにもなるため、表示されます。
<xdofo:inline-total display-condition="last" name="vDummy">
Last page footer
</xdofo:inline-total>


【制限事項】
xdofo:inline-totalはPDFのフォーマッティング時に実行されるため、PDF以外の出力では使用できません。また、テンプレートの呼び出しなどはフォーマッティング以前に完了される必要があるため、xdofo:inline-total内に記載することはできません。
フォーマッティング時に実行される fo:page-number 等のオブジェクトは使用できます。つまり、以下の記載は有効です。
<xdofo:inline-total display-condition="last" name="vDummy">
<fo:page-number()>
</xdofo:inline-total>




[Summary]
The example above shows how to switch the header and footer based on the page condition. In many cases, The first page becomes the last page (i.e. the report is one page only) raise a problem.


BI Publisher provides header/footer solutions such as <?start:body?>, but its function is not strong enough to fill the customer's requirement.


[Requirements]
Figure 1 through to Figure 4 shows the typical requirement.
If report has several pages, it shows different header / footer on the first, middle and the last page (Figure 1 to 3).
If report is only one page, it shows the first page header and the last page footer (Figure 4).


[xdofo:inline-total object]
To fill the requirement above, use xdofo:inline-total object. You can use it with the nested construct.
The sample rtf template is available here.


For the details, please refer the manual below:


[Restriction]
Since xdofo:inline-total is extracted in PDF formatting phase, other format - RTF, Excel etc - is not supported.
Things that need to be organized before the PDF formatting phase, such as calling template, cannot be included in xdofo:inline-total object.

0 件のコメント:

コメントを投稿