XMLデータをXSLT変換しページ上に表示する

説明

XMLデータをXSLTで変換しページ上に表示するにはGXslt.create()で適用するXSLTデータを指定しオブジェクトを生成します。transformToHtml()を使ってXMLデータを変換します。最初のパラメータがXMLデータ、次がページ上の表示先になります。

注意:Safari 2では正常に動作しません。

逆引きGoogle Maps APIリファレンス  詳しい解説などは逆引きGoogle Maps APIリファレンス、またはGoogle Maps APIリファレンスを参照してください。

サンプルコード [実行]

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://maps.google.com/maps?file=api&v=1&key=ABQIAAAAasAJryKxWJnBFVJa487d9hTHGAxTVT7IRADYa-JdYz7xQ8IQZBSthgDZdggYpQHsmm6WYtHstQFfLA" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
httpObj = GXmlHttp.create();
httpObj.open("get", "sample.xsl");
httpObj.onreadystatechange = function() {
if ((httpObj.readyState == 4) && (httpObj.status == 200)) {
xsltData = GXslt.create(httpObj.responseXML);
httpObj2 = GXmlHttp.create();
httpObj2.open("get", "sample.xml");
httpObj2.onreadystatechange = function() {
if ((httpObj2.readyState == 4) && (httpObj.status == 200)) {
xmlData = httpObj2.responseXML;
xsltData.transformToHtml(xmlData, document.getElementById("result"));
}
}
httpObj2.send(null);
}
}
httpObj.send(null);
//]]>
</script>
</head>
<body>
<div id="result">読み込み中...</div>
</body>
</html>