住所録のテンプレートを作成するには、XVCD内で住所録用のXML文書テンプレートを定義します。XML文書テンプレートは、
xvcd:xvcd要素の子要素として記述した
xvcd:document-template要素の内容に定義します。
xvcd:document-template要素の内容には、文書テンプレートとして使用したいXML文書フラグメントを記述します。今回の場合、文書テンプレートとして使用したいのは、次のXML文書フラグメントです。
<ab:addressbook xmlns:ab="http://xmlns.example.com/developer/tutorial/addressbook">
<ab:entry>
<ab:person></ab:person>
<ab:address></ab:address>
</ab:entry>
</ab:addressbook>
文書テンプレートには名前を付ける必要があります。ユーザーが文書テンプレートを使用するときは、[ファイル - 新規作成]を選択すると表示される[新規作成]ダイアログボックスで、使用する文書テンプレートの名前を選択します。
住所録の文書テンプレート定義は以下のようになります。 住所録の文書テンプレートの名前は、「AddressBook」としています。
<xvcd:document-template name="AddressBook" target="common">
<ab:addressbook xmlns:ab="http://xmlns.example.com/developer/tutorial/addressbook">
<ab:entry>
<ab:person></ab:person>
<ab:address></ab:address>
</ab:entry>
</ab:addressbook>
</xvcd:document-template>
xvcd:document-template要素のtarget属性の値には、commonを指定します。target属性を省略したり、target属性の値にprivateを指定したりすると、XML文書テンプレートをxfyプラットフォームに登録できないので注意してください。
ここまでの内容をAddressBook.xvcdに反映すると、次のようになります。 強調文字で表記した箇所が、追加・変更された箇所です。
<?xml version="1.0"?>
<xvcd:xvcd
xmlns:xvcd="http://xmlns.xfy.com/xvcd"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ab="http://xmlns.example.com/developer/tutorial/addressbook"
version="1.0">
<!-- =============================================
文書テンプレート記述
=============================================== -->
<xvcd:document-template name="AddressBook" target="common">
<ab:addressbook xmlns:ab="http://xmlns.example.com/developer/tutorial/addressbook">
<ab:entry>
<ab:person></ab:person>
<ab:address></ab:address>
</ab:entry>
</ab:addressbook>
</xvcd:document-template>
<!-- =============================================
ボキャブラリ定義
=============================================== -->
<xvcd:vocabulary name="AddressBook" match="ab:addressbook" call-template="root"/>
<!-- =============================================
テンプレートルール
=============================================== -->
<xvcd:template name="root">
<html>
<body>
<table border="1" width="100%">
<tr>
<th width="150">
Name
</th>
<th>
Address
</th>
</tr>
<xvcd:apply-templates select="ab:entry"/>
</table>
</body>
</html>
</xvcd:template>
<xvcd:template match="ab:entry">
<tr>
<td>
<xvcd:apply-templates select="ab:person"/>
</td>
<td>
<xvcd:apply-templates select="ab:address"/>
</td>
</tr>
</xvcd:template>
<xvcd:template match="ab:person">
<xvcd:text-of select="." filler="Enter the name here."/>
</xvcd:template>
<xvcd:template match="ab:address">
<xvcd:text-of select="." filler="Enter the address here."/>
</xvcd:template>
</xvcd:xvcd>
編集が完了したら、AddressBook3.xvcdとして保存します。