net_lover [原作]
下面就是簡單的例子,這裡提供2中方法:
test.htm
<SCRIPT>
//裝載數據
x = "<r><a name='net_lover'>aaaaaaaaaaa</a> <b>bbbbbbb</b><a>aaaaaaaaaaa</a><b>bbbbbbb</b></r>"
var source = new ActiveXObject("MsXML2.DOMDocument");
source.async = false;
source.loadXML(x)
alert(source.XML)
// 裝載樣式單
var stylesheet = new ActiveXObject("MsXML2.DOMDocument");
stylesheet.async = false;
stylesheet.resolveExternals = false;
stylesheet.load("style.xsl");
alert(stylesheet.XML)
// 創建結果對象
var result = new ActiveXObject("MsXML2.DOMDocument");
result.async = false;
// 把解析結果放到結果對象中方法1
source.transformNodeToObject(stylesheet, result);
alert(result.XML)
// 把解析結果放到結果對象中方法2
result2 = ""
result2 = source.transformNode(stylesheet);
source.loadXML(result2)
alert(source.XML)
</SCRIPT>
style.xsl
<?XML version="1.0"?>
<xsl:stylesheet version="1.0" XMLns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method = "xml" omit-XML-declaration = "yes" indent = "yes"/>
<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>