这是我的 xml 文件:-
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="final.xsl"?>
<root>
<child1 entity_id = "1" value= "Asia">
<child2 entity_id = "2" value = "india">
<child3 entity_id = "3" value = "Gujarat">
<child5 entity_id = "5" value ="Rajkot"></child5>
</child3>
<child4 entity_id = "4" value = "Rajshthan">
<child6 entity_id = "6" value = "Ajmer"></child6>
</child4>
</child2>
</child1>
</root>
这是我的 XSLT 文件:-
<xsl:template match="*">
<xsl:for-each select="//child2">
<xsl:value-of select="*"/>
<xsl:value-of select="@value" />
</xsl:for-each>
这是我的 html 代码:-
<script>
function loadXMLDoc(dname)
{
if (window.XMLHttpRequest)
{
xhttp=new XMLHttpRequest();
}
else
{
xhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xhttp.open("GET",dname,false);
xhttp.send("");
return xhttp.responseXML;
}
function displayResult()
{
xml=loadXMLDoc("final.xml");
xsl=loadXMLDoc("books05.xsl");
// code for IE
if (window.ActiveXObject)
{
xml.addParameter("rss", test);
ex=xml.transformNode(xsl);
document.getElementById("load").innerHTML=ex;
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xsltProcessor=new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
resultDocument = xsltProcessor.transformToFragment(xml,document);
document.getElementById("load").appendChild(resultDocument);
}
}
</script>
<body onload="displayResult()">
<div id="load" />
</body>
输出是: -
India
现在我想在印度设置点击事件...点击印度然后显示那里的子元素,如古吉拉特邦和拉杰什坦......当显示古吉拉特邦和拉杰什坦时隐藏印度......