mb_language("uni"); mb_internal_encoding("utf-8"); mb_http_input("auto"); mb_http_output("utf-8"); ?>
前回は,OpenOfficeのXMLボキャブラリであるOpenDocument Format(ODF)の仕様書を和訳する作業で訳語の確認に用いているエクスポート(輸出)の方法についてお話ししました。今回は,そのエクスポートによって得られた訳語データ(XML文書インスタンス)をスプレッドシート文書へインポート(輸入)するフィルターについてお話しします。言い換えれば,OpenOfficeのWriter(ワープロ)からCalc(スプレッドシート)へデータを移す処理の話です。この訳語データを移す処理の概念を図1に示します。
先ず,図2のようにワープロで脚注として書いた訳語を図3で示す文書型でエクスポートします。この文書型では,全体をbook要素とし,その中で脚注を表すfootnote要素が繰り返されるものとします。一つの脚注は,脚注番号(no要素),訳語(text要素),原語(source要素)で表します。例えば,図2において「書式付き番号付け」という訳語は,脚注番号が「299」で,原語が「formatted number」ですから,エクスポートの結果(XSL変換の結果)は,図4に示すように「
▼図1 訳語データを移す処理
▼図2 ODF仕様書の一部(和文)
▼図3-1 訳語を表す文書型(DTDによる表現)
<!DOCTYPE book [
<!ELEMENT book (footnote+) >
<!ELEMENT footnote (no,text,source) >
]>
▼図3-2 訳語を表す文書型(XML Schemaによる表現)
<schema xmlns='http://www.w3.org/1999/XMLSchema'
targetNamespace='http://www.jagat.or.jp/xml/oo'
xmlns:k='http://www.jagat.or.jp/xml/oo'>
<element name="book">
<complexType content="elementOnly">
<element ref="k:footnote" maxOccurs="unbounded">
</complexType>
</element>
<element name="footnote">
<complexType content="elementOnly">
<sequence>
<element ref="k:no">
<element ref="k:text">
<element ref="k:source">
</sequence>
</complexType>
</element>
</schema>
▼図4 訳語データ(エクスポートの結果)
<?xml version="1.0" encoding="UTF-8"?>
<book xmlns="http://www.jagat.or.jp/xml/oo">
(略)
<footnote>
<no>297</no><text>見出し番号付け</text><source>header numbering</source>
</footnote>
<footnote>
<no>298</no><text>リスト体裁</text><source>list-style</source>
</footnote>
<footnote>
<no>299</no><text>書式付き番号付け</text><source>formatted number</source>
</footnote>
<footnote>
<no>300</no><text>支持する</text><source>to support</source>
</footnote>
(略)
</book>
エクスポートして得られた訳語データをスプレッドシートへインポートする話に入る前に,なぜワープロからスプレッドシートへ訳語データを直接移せないのか,という疑問を持つかもしれません。つまり,ワープロで書いた脚注をコピー(複製)してからスプレッドシートにペースト(貼り付け)すれば済むのではないか,と考える方もおられるでしょう。なるほど,それはできることですが,脚注番号,訳語,原語の組が数百組あることを想像してください。それは誰もしたくない作業のはずです。また,訳語データを外部のファイルへ出力しないで,内部的なファイルを経由できないか,という疑問を持つかもしれません。それはフィルターでは残念ながらできません。マクロを使えばできそうですが,それはまだ調べていません。
さて,インポート・フィルターを作るには,先ず,対象となるスプレッドシートがどのようにODFで表されるか,を知る必要があります。インポート結果を表すスプレッドシートが図5のようなものだとします。図5のスプレッドシートを表すODFの部分を図6に示します。ODFのtable:table要素は,HTMLのTABLE要素によく似ており,table:table-column要素はCOL要素に,table:table-row要素はTR要素に,table:table-cell要素はTD要素またはTH要素に機能的に対応します。エクスポートと違って,インポートでは,表示のための詳細な体裁(style)の指定が必要になります。
▼図5 スプレッドシート
▼図6 スプレッドシートを表すODFの部分
<table:table table:style-name="表体裁">
<table:table-column table:style-name="縦列1体裁"/>
<table:table-column table:style-name="縦列2体裁"/>
<table:table-column table:style-name="縦列3体裁"/>
<table:table-row table:style-name="見出し行体裁">
<table:table-cell table:style-name="見出し1体裁" office:value-type="string">
<text:p text:style-name="見出し1内容体裁">脚注番号</text:p>
</table:table-cell>
<table:table-cell table:style-name="見出し2体裁" office:value-type="string">
<text:p text:style-name="見出し2内容体裁">訳語</text:p>
</table:table-cell>
<table:table-cell table:style-name="見出し3体裁" office:value-type="string">
<text:p text:style-name="見出し3内容体裁">原語</text:p>
</table:table-cell>
</table:table-row>
<table:table-row table:style-name="データ行体裁">
<table:table-cell table:style-name="データセル1体裁" office:value-type="string">
<text:p text:style-name="データセル1内容体裁">297</text:p>
</table:table-cell>
<table:table-cell table:style-name="データセル2体裁" office:value-type="string">
<text:p text:style-name="データセル2内容体裁">見出し番号付け</text:p>
</table:table-cell>
<table:table-cell table:style-name="データセル3体裁" office:value-type="string">
<text:p text:style-name="データセル3内容体裁">header numbering</text:p>
</table:table-cell>
</table:table-row>
<table:table-row table:style-name="データ行体裁">
<table:table-cell table:style-name="データセル1体裁" office:value-type="string">
<text:p text:style-name="データセル1内容体裁">298</text:p>
</table:table-cell>
<table:table-cell table:style-name="データセル2体裁" office:value-type="string">
<text:p text:style-name="データセル2内容体裁">リスト体裁</text:p>
</table:table-cell>
<table:table-cell table:style-name="データセル3体裁" office:value-type="string">
<text:p text:style-name="データセル3内容体裁">list-style</text:p>
</table:table-cell>
</table:table-row>
(略)
</table:table>
図4の訳語データを図6のスプレッドシートを表すODFへXSL変換するインポート・フィルターは,図7のようになります。なお,紙面の関係から「書体の宣言」と「体裁の指定」の部分は割愛し,そのことは次回にお話しすることにしましょう。
▼図7 インポート・フィルター
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
xmlns:k="http://www.jagat.or.jp/xml/oo">
<xsl:output method="xml" omit-xml-declaration="no" indent="yes" encoding="UTF-8"/>
<xsl:template match="/">
<office:document-content>
<office:font-face-decls>
書体の宣言
</office:font-face-decls>
<office:automatic-styles>
体裁の指定
</office:automatic-styles>
<office:body>
<office:spreadsheet>
<table:table table:style-name="表体裁">
<table:table-column table:style-name="縦列1体裁"/>
<table:table-column table:style-name="縦列2体裁"/>
<table:table-column table:style-name="縦列3体裁"/>
<table:table-row table:style-name="見出し行体裁">
<table:table-cell table:style-name="見出し1体裁" office:value-type="string">
<text:p text:style-name="見出し1内容体裁">脚注番号</text:p>
</table:table-cell>
<table:table-cell table:style-name="見出し2体裁" office:value-type="string">
<text:p text:style-name="見出し2内容体裁">訳語</text:p>
</table:table-cell>
<table:table-cell table:style-name="見出し3体裁" office:value-type="string">
<text:p text:style-name="見出し3内容体裁">原語</text:p>
</table:table-cell>
</table:table-row>
<xsl:apply-templates/>
</table:table>
</office:spreadsheet>
</office:body>
</office:document-content>
</xsl:template>
<xsl:template match="//k:footnote">
<table:table-row table:style-name="データ行体裁">
<table:table-cell style:name="データセル1体裁" office:value-type="string">
<text:p text:style-name="データセル1内容体裁">
<xsl:value-of select="./k:no"/>
</text:p>
</table:table-cell>
<table:table-cell style:name="データセル2体裁" office:value-type="string">
<text:p text:style-name="データセル2内容体裁">
<xsl:value-of select="./k:text"/>
</text:p>
</table:table-cell>
<table:table-cell style:name="データセル3体裁" office:value-type="string">
<text:p text:style-name="データセル3内容体裁">
<xsl:value-of select="./k:source"/>
</text:p>
</table:table-cell>
</table:table-row>
</xsl:template>
</xsl:stylesheet>
前回の文中において名前空間の指定とXSL変換の結果表示が誤っていることに気付きました。今回は正しく書いてあります。お詫びして訂正します。
▲このページのTOPへ