Tuesday, January 18, 2011
InDesign では XML文書を流し込み組版するための仕組みが予め備わっています。
一つの方法は、CALSテーブルを使う方法(9a819c91-2041-466f-a8fb-ac73a920e16b.html)ですが、
これは、テーブルのセル内のコンテンツは単なる文字列としてしか扱うことができないようなので不便です。
別の方法として、InDesign専用のテーブルタグ(Table,Cellなど)を使う方法です。
これは、Adobe から提供されているInDesignとXMLに関するドキュメント indesign_and_xml_technical_reference.pdf を読めばわかります。
indesign\_and\_xml\_technical\_reference.pdf は http://www.adobe.com/jp/products/indesign/scripting/ から入手可能。
"InDesign x 表組 x XML流し込み" の参考情報: http://www.milligramme.cc/wp/archives/3424
<cell aid:ccolwidth=”セル幅”>(ポイント指定にしかならない)・・・と!→ ミリで指定した数値は 2.835 倍すると ポイントに変換できる。
変換表
このエントリでは、InDesign 用の表組み XML の記述例とXSLTによる変換のメモです。
h3. 結論: table.xml
InDesignにテーブルを流し込むには要するに次のようなXMLを書けばよい。
<?xml version="1.0" encoding="UTF-8"?>
<story xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/" xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/">
<Table aid:table="table" aid:trows="3" aid:tcols="2">
<Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1" aid:ccolwidth="150.0">見出しA</Cell>
<Cell aid:table="cell" aid:theader="" aid:crows="1" aid:ccols="1" aid:ccolwidth="150.0">見出しB</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="150.0">内容A-1</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="150.0">内容B-1</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="150.0">内容A-2</Cell>
<Cell aid:table="cell" aid:crows="1" aid:ccols="1" aid:ccolwidth="150.0">内容B-2</Cell>
</Table>
</story>
という手順。
名前空間なしで XML を生成しておく。
<?xml version="1.0" encoding="UTF-8"?>
<story>
<Table table="table" trows="3" tcols="2">
<Cell table="cell" theader="" crows="1" ccols="1" ccolwidth="150.0">見出しA</Cell>
<Cell table="cell" theader="" crows="1" ccols="1" ccolwidth="150.0">見出しB</Cell>
<Cell table="cell" crows="1" ccols="1" ccolwidth="150.0">内容A-1</Cell>
<Cell table="cell" crows="1" ccols="1" ccolwidth="150.0">内容B-1</Cell>
<Cell table="cell" crows="1" ccols="1" ccolwidth="150.0">内容A-2</Cell>
<Cell table="cell" crows="1" ccols="1" ccolwidth="150.0">内容B-2</Cell>
</Table>
</story>
以下の toind.xsl を使用して Table,Cell 要素の属性に対して一括で 名前空間を追加する。
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:aid="http://ns.adobe.com/AdobeInDesign/4.0/"
xmlns:aid5="http://ns.adobe.com/AdobeInDesign/5.0/"
version="1.0">
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template name="table-proc" >
<xsl:element name="{name()}" >
<xsl:for-each select="@*">
<xsl:attribute name="aid:{name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:for-each>
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="Cell">
<xsl:call-template name="table-proc" />
</xsl:template>
<xsl:template match="Table">
<xsl:call-template name="table-proc" />
</xsl:template>
</xsl:stylesheet>
table-src.xml に toind.xsl を(XSLTを使って)適用すると、 table.xml になります。
この xsl の記述ポイントは...
* Table,Cellの各要素の属性に aid: を 手間なく,簡潔な記述で 追加したい
* TableとCell両方ともの処理内容が同じなので XSLT の名前付きテンプレートを使うという点です。