さて一番最初はfo:blockです.あまりおもしろくないかもしれませんがfo:blockは、fo:page-sequence/fo:flowの中で重要な位置を占めるブロックコンテンツです.XSL-FO仕様(http://www.w3.org/TR/xsl/)だと、fo:root/fo:page-sequence/fo:flowの中でブロックレベルのFO(フォーマッティングオブジェクト)とされるものは、次があります.
fo:block
fo:block-container
fo:table-and-caption
fo:table
fo:list-block
fo:block-container
fo:table-and-caption
fo:table
fo:list-block
けっこうありますね.でもMicrosoft Wordでは、基本的に本文を構成するブロックレベルの要素は
w:p (段落)
w:table (表)
w:table (表)
だけです.Wordではリストは段落の亜種です.fo:block-containerに該当するものは、Wordではシェープのテキストボックスですかね?こうやって比較してみると結構おもしろいです.
さてfo:blockは言ってみれば「段落」です.例えば
DITA: <p>
DocBook: <para>
DocBook: <para>
はXML⇒XSL-FOのスタイルシートでは間違いなくfo:blockに変換します.fo:blockはテキストかインライン(fo:inline)を格納しますが、「段落」を修飾する様々なプロパティを持っています(http://www.w3.org/TR/xsl/#fo_block).このプロパティにはWordの「段落属性」と似ているものを見つけることができます.
break-after, break-before: WordのLine and Page Breaksの「Page break before」
⇒Wordでは段落のあとで改ページというのはできない.
keep-together: WordのLine and Page Breaksの「Keep lines together」
keep-with-next, keep-with-previous: WordのLine and Page Breaksの「Keep with next」
⇒Wordでは前の要素とくっつけるということはできない.
⇒Wordでは段落のあとで改ページというのはできない.
keep-together: WordのLine and Page Breaksの「Keep lines together」
keep-with-next, keep-with-previous: WordのLine and Page Breaksの「Keep with next」
⇒Wordでは前の要素とくっつけるということはできない.
line-height: WordのIndent and spacingの「Spacing - Line spacing」
⇒FOでは「行の高さ」ですが、Wordでは行間のスペーシングです.ここの考え方はFOとWordでは全然違います.FOには「行間」はありません.あくまで行の高さを指定です.
⇒FOでは「行の高さ」ですが、Wordでは行間のスペーシングです.ここの考え方はFOとWordでは全然違います.FOには「行間」はありません.あくまで行の高さを指定です.
text-lign: WordのIndent and spacingの「General - Alignment」
start-indent, end-indent: WordのIndent and spacingの「Indentation - Left, Right」
space-before, space-after: WordのIndent and spacingの「Spacing - Before, After」
start-indent, end-indent: WordのIndent and spacingの「Indentation - Left, Right」
space-before, space-after: WordのIndent and spacingの「Spacing - Before, After」
などなど.でももちろん違う点も山ほどあります.XSL-FOとWordですから...
さて基本的なfo:blockですが、ちょっとしたテクニックを紹介したいと思います.たとえば本文の文字サイズとテーブル内の文字サイズをどのように切り替えられるでしょうか?段落のスタイルシートは例えばDocBookだったら次のようになるでしょうか?
<xsl:attribute-set name="atsPara">
<xsl:attribute name="font-size">11pt</xsl:attribute>
<xsl:attribute name="font-family">Times New Roman</xsl:attribute>
<xsl:attribute name="text-align">start</xsl:attribute>
<xsl:attribute name="space-before">2mm</xsl:attribute>
</xsl:attribute>
<xsl:attribute name="font-size">11pt</xsl:attribute>
<xsl:attribute name="font-family">Times New Roman</xsl:attribute>
<xsl:attribute name="text-align">start</xsl:attribute>
<xsl:attribute name="space-before">2mm</xsl:attribute>
</xsl:attribute>
<xsl:template match="para">
<fo:block use-attribute-sets="atsPara">
<xsl:apply-templates/>
</fo:block>
</xsl:template>
<fo:block use-attribute-sets="atsPara">
<xsl:apply-templates/>
</fo:block>
</xsl:template>
本文だけだったらこれでもいいのですが、表の中は少しフォントサイズを小さくしたいしスペーシングも小さくとりたいということがよくあります.こんな時にスタイルを切り替えるのは手間でしょうがありません.
<xsl:template match="para">
<xsl:choose>
<xsl:when test="ancestor::entry">
<fo:block use-attribute-sets="atsParaInTable">
<xsl:apply-templates/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block use-attribute-sets="atsPara">
<xsl:apply-templates/>
</fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:choose>
<xsl:when test="ancestor::entry">
<fo:block use-attribute-sets="atsParaInTable">
<xsl:apply-templates/>
</fo:block>
</xsl:when>
<xsl:otherwise>
<fo:block use-attribute-sets="atsPara">
<xsl:apply-templates/>
</fo:block>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
私は上でいうところのatsParaはほぼ「空」で良いと考えています.次のようにします.
1.文書全体で共通の文字サイズはfo:rootに指定する.
<fo:root font-size="11pt"
font-family="Times New Roman"
text-align="start">
<fo:root font-size="11pt"
font-family="Times New Roman"
text-align="start">
2.表の場合もfo:tableに指定する.
<fo:table font-size="9.5pt">
<fo:table font-size="9.5pt">
これらは、font-sizeやfont-family、text-alignが継承プロパティであることを利用しています.
3.そして段落スタイルはspace-beforeだけにします.
<xsl:attribute-set name="atsPara">
<xsl:attribute name="space-before">1.5122em - 3.8673mm</xsl:attribute>
</xsl:attribute>
<xsl:attribute name="space-before">1.5122em - 3.8673mm</xsl:attribute>
</xsl:attribute>
この指定だとemサイズ(そのときのフォントサイズ)を参照しますので、本文中だとspace-before="2mm"でテーブルの中だとspace-before="1.2mm"になります.つまりスタイルを本文用、テーブル用と二つ作って使い分ける必要がありません.一つだけで済みます.
ちょっと便利だと思いますがいかがでしょう?