DITA 1.3の便利なフィルタリング属性deliveryTarget

DITA1.3はなかなか勉強する時間がありません.でも今度正式なスキーマになるRELAX NGで特殊化のサンプルを作ってみました.さてそれで実際に文書を作り、どんなことがDITA 1.3でできるのか考えていたとき、deliveryTargetというフィルタリングの属性が加わっているのに気が付きました.

3.12.1.2 Metadata attribute group

サンプルはここにあります.
2.2.3.8.4 Example: Defining values for @deliveryTarget

これはちょっと長いので、PDF出力でWEB用、カラー印刷用、モノクロ印刷用という簡単なSubjectSchemaを作ってみました.(私はあまりsubjectSchemeを作ったことがないのですが、これで合っていると思います)

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="urn:oasis:names:tc:dita:rng:subjectScheme.rng" schematypens="http://relaxng.org/ns/structure/1.0"?> 
<subjectScheme>
    <subjectdef keys="output-type" navtitle="Output Type">
        <subjectdef keys="pdf-web" navtitle="PDF For WEB"/>
        <subjectdef keys="pdf-print" navtitle="PDF For Print">
            <subjectdef keys="pdf-print-mono"  navtitle="PDF For Monochrome Printing"/>
            <subjectdef keys="pdf-print-color"  navtitle="PDF For Color Printing"/>
        </subjectdef>
    </subjectdef>
    <enumerationdef>
        <attributedef name="deliveryTarget"/>
        <subjectdef keyref="output-type"/>
    </enumerationdef>
</subjectScheme>

ではいったいどういう場面でこれを使うのかといいますと、特に画像の場合に有効に使えました.PDFの作り分けをするときにCMSを持っていらっしゃる方でしたら、元をEPSで作っておき、用途に応じてCMSが勝手にチェックアウトしてくれるような機能があります.でも手作りでやっているような場合、WEB用、カラー印刷用、モノクロ印刷用というような画像の切り替えは意外と面倒なものです.

例えば、画像を次のようにkeydefで定義しておけば便利です.この例ではWEB用にはSVG画像を、カラー印刷用にはカラーのPDFを、モノクロ印刷用にはモノクロのPDFを"COVER1-BACKGROUND"というキー値にマッピングしています.

[keydef_image.ditamap]

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="urn:oasis:names:tc:dita:rng:map.rng" schematypens="http://relaxng.org/ns/structure/1.0"?> 
<map>
 <title>Image Key Definition</title>
 <keydef keys="COVER1-BACKGROUND" navtitle="Cover 1 - background image" href="topics-en/image/cover_vector1.svg" format="svg" deliveryTarget="pdf-web"/>
 <keydef keys="COVER1-BACKGROUND" navtitle="Cover 1 - background image" href="topics-en/image/cover_vector1.pdf" format="pdf" deliveryTarget="pdf-print-color"/>
 <keydef keys="COVER1-BACKGROUND" navtitle="Cover 1 - background image" href="topics-en/image/cover_vector1_mono.pdf" format="pdf" deliveryTarget="pdf-print-mono"/>
 ...
</map>

DITAインスタンスからは単に次のように参照すれば済みます.

<image keyref="COVER1-BACKGROUND" placement="break"/>

あとは.ditavalファイルを作って、出力するPDF毎に切り替えます.このパラメータはDITA-OTを起動するときのコマンドラインで-Dargs.filterで指定します.

[print_color.ditaval]
<?xml version="1.0" encoding="UTF-8"?>
<val>
    <prop action="exclude" att="deliveryTarget" val="pdf-web" />
    <prop action="include" att="deliveryTarget" val="pdf-print" />
    <prop action="include" att="deliveryTarget" val="pdf-print-color" />
    <prop action="exclude" att="deliveryTarget" val="pdf-print-mono" />
</val>

[print_mono.ditaval]
<?xml version="1.0" encoding="UTF-8"?>
<val>
    <prop action="exclude" att="deliveryTarget" val="pdf-web" />
    <prop action="include" att="deliveryTarget" val="pdf-print" />
    <prop action="exclude" att="deliveryTarget" val="pdf-print-color" />
    <prop action="include" att="deliveryTarget" val="pdf-print-mono" />
</val>

[web.ditaval]
<?xml version="1.0" encoding="UTF-8"?>
<val>
    <prop action="include" att="deliveryTarget" val="pdf-web" />
    <prop action="exclude" att="deliveryTarget" val="pdf-print" />
    <prop action="exclude" att="deliveryTarget" val="pdf-print-color" />
    <prop action="exclude" att="deliveryTarget" val="pdf-print-mono" />
</val>

実際にやってみましたが、オーサリングをなんら変更することなく.ditavalファイルを切り替えるだけで、3種類のPDFが自動的に作られるのにはチョット感動しました.なかなかいいかもです.