.NET(c#)怎么样生成XML就先不讲了
.NET生成的XML:Menu.xml
<Root>
<TreeNode Title="zeditor1" Href="http://www.google.cn/" target="_blank" >
<TreeNode Title="zeditor01" Href=http://www.yahoo.com.cn/" target="_blank"/>
</TreeNode>
<TreeNode Title="zeditor2" Href="http://www.baidu.com/ target="_blank" />
</Root>
XSLT:sitemenu.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Root">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="TreeNode">
<ul style="list-style:none;margin:0px 20px;">
<xsl:for-each select=".">
<li style="list-style:none;">
<a>
<xsl:attribute name="href">
<xsl:value-of select="@Href"/>
</xsl:attribute>
<xsl:attribute name="target">
<xsl:value-of select="@target"/>
</xsl:attribute>
<xsl:value-of select="@Title"/>
</a>
<xsl:apply-templates/>
</li>
</xsl:for-each>
</ul>
</xsl:template>
</xsl:stylesheet>
生成后通过JS解析:
loadXML("Menu.xml,"sitemenu.xsl");
function loadXML(XMLf,xslf)
{
try
{
var myXML=new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
myXML.async=false;
myXML.load(XMLf);
var myxsl=new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
myxsl.async=false;
myxsl.load(xslf);
HTML=myXML.transformNode(myxsl);
document.write(HTML);
}
catch (exception)
{
alert(exception.description);
}
}