ページの先頭行へ戻る
Interstage Interaction Manager V9.1.1 Ajaxフレームワーク ユーザーズガイド

5.11.3 XSLの作成(マッシュアップ開発例)

スクレイピングツールを利用して、Webアプリケーションをスクレイピングし、XSLファイルを作成します。
スクレイピングツールの操作方法については、“付録G スクレイピングツール”を参照してください。

XSL作成時には、以下の情報を入力します。

HTML形式のデータは、HTMLアダプタで正規化され、XHTML形式のデータとして変換されます。スクレイピングツールを利用すると、XSLTプロセッサを使用して、XHTML形式のデータから必要な部分を切り出すことができます。

XSLファイルの例

<?xml version="1.0" encoding="UTF-8"?>
<!-- XSLT stylesheet generated by IIM on 2009/08/17 -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
 xpath-default-namespace="http://www.w3.org/1999/xhtml">
<xsl:output method="xml" omit-xml-declaration="yes" indent="yes" />

<!-- create tags for the document root -->
<xsl:template match="/">
<html>
<xsl:copy-of select="/html[1]/body[1]/table[1]
" />
</html>
</xsl:template>

<!-- default text template -->
<xsl:template priority="0" match="text()" />

</xsl:stylesheet>

切り出されたデータの例

<html>
  <table border="1">
    <tr>
      <th>予定日</th><th>時間帯</th><th>表題</th>
    </tr>
    <tr>
      <td>2008/10/03</td><td>09:30 - 12:00</td><td>健康診断</td>
    </tr>
    <tr>
      <td>2008/10/16</td><td>09:30 - 17:30</td><td>私用で休み</td>
    </tr>
    <tr>
      <td>2008/10/19</td><td>19:30 - 21:30</td><td>同窓会</td>
    </tr>
  </table>
</html>

JSON形式に変換後のデータ(注)

{
  "tagName":"html",
  "childNodes":[
    {"tagName":"table",
     "attributes":{"border":"1"},
     "childNodes":[
       {"tagName":"tr",
        "childNodes":[
          {"tagName":"th","childNodes":["予定日"]},
          {"tagName":"th","childNodes":["時間帯"]},
          {"tagName":"th","childNodes":["表題"]}
       ]}, 
       {"tagName":"tr",
        "childNodes":[
          {"tagName":"td","childNodes":["2008/10/03"]},
          {"tagName":"td","childNodes":["09:30 - 12:00"]},
          {"tagName":"td","childNodes":["健康診断"]}
       ]}, 
       {"tagName":"tr",
        "childNodes":[
          {"tagName":"td","childNodes":["2008/10/16"]},
          {"tagName":"td","childNodes":["09:30 - 17:30"]},
          {"tagName":"td","childNodes":["私用で休み"]}
       ]}, 
       {"tagName":"tr",
        "childNodes":[
          {"tagName":"td","childNodes":["2008/10/19"]},
          {"tagName":"td","childNodes":["19:30 - 21:30"]},
          {"tagName":"td","childNodes":["同窓会"]}
       ]}
     ]
    }
  ]
}

注) 実際のデータに改行は含まれません。