ソースの Practice.xml を javascript から html に変換し、生成された html を空の DIV 要素に追加するための Practice.xsl ファイルを作成しました。
ここに Practice.xml があります
<feed>
<feedback>
<user>Naresh</user>
<date>12 Oct, 2009</date>
<comments>This blog has no stuff to rate it</comments>
</feedback>
<feedback>
<user>Pokuri</user>
<date>21 Dec, 2009</date>
<comments>Naresh is right</comments>
</feedback>
<feedback>
<user>Subbu</user>
<date>30 Dec, 2009</date>
<comments>I don't agree with both Naresh n Pokuri</comments>
</feedback>
</feed>
これが Practice.xsl です。
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html" indent="yes"/>
<xsl:template match="feed/feedback">
<html>
<head>
<title>Feedback Forum</title>
</head>
<body>
<span style="display:block; padding: 5px 10px; background-color: #C9F0F9; width: 100%; margin-top:10px; border-left:10px solid #F9EBC9; border-bottom: 1px solid #000000;"><xsl:apply-templates select="user"/> on <xsl:apply-templates select="date"/></span>
<span style="display:block; padding: 5px 10px; background-color: #CDF5CD; width: 100%; border-left:10px solid #F9EBC9;"><xsl:apply-templates select="comments"/></span>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Firefox で XSLT 変換を使用するための JavaScript は次のとおりです。
function listOrders(){
var XSLT = loadXSLT("Practice.xsl");
var trasformedText;
if(window.ActiveXObject){
trasformedText = XMLDOM.transformNode(XSLT);
document.getElementById("rightDIV").innerHTML=trasformedText;
} else if(document.implementation && document.implementation.createDocument){
**xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(XSLT);
trasformedText = xsltProcessor.transformToFragment(XMLDOM, document);
document.getElementById("rightDIV").appendChild(trasformedText);**
} else {
alert("Sorry your browser may not support xsl transformation.\n+Please check your browser documentation for further help");
}
}
プロが問題を簡単に特定できる相対イメージ
Firefox の場合: http://img97.imageshack.us/img97/8509/firefoxk.jpg