XMLファイルがあります
<?xml version="1.0" encoding="ISO-8859-1"?>
<childrens>
<child entity_id="1" value="Root Catalog" parent_id="0">
<child entity_id="2" value="Apparel" parent_id="1">
<child entity_id="4" value="Shirts" parent_id="2"/>
<child entity_id="5" value="Pants" parent_id="2"/>
</child>
<child entity_id="3" value="Accessories" parent_id="1">
<child entity_id="6" value="Handbags" parent_id="3"/>
<child entity_id="7" value="Jewelry" parent_id="3"/>
</child>
.
.
.
<child entity_id='1110' value="test" parent_is="1109">
<child entity_id='1111' value="test0" parent_is="1110">
<child entity_id="1005" value="test1" parent_is="1111"/>
<child entity_id="1006" value="test12" parent_is="1111"/>
<child entity_id="1007" value="test123" parent_is="1111"/>
<child>
</child>
<child >
</childrens>
今、私はこのXSLコードを書きました
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>
<xsl:param name="selected" />
<xsl:template match="/*">
<xsl:apply-templates select="*[not($selected)] | //*[@entity_id = $selected]/*" />
</xsl:template>
<xsl:template match="*">
<span onclick="displayResult('{@entity_id}');">
<xsl:value-of select="concat(@value, ' ')"/><br/>
</span>
</xsl:template>
</xsl:stylesheet>
HTMLは
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Region</title>
<link href='style.css' rel='stylesheet' type='text/css'/>
<script>
var xml = loadXMLDoc("tree.xml");
var xsl = loadXMLDoc("try.xsl");
function loadXMLDocActiveX(location) {
var doc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
doc.async = false;
doc.load(location);
return doc;
}
function loadXMLDocOther(location) {
xhttp = new XMLHttpRequest();
xhttp.open("GET", location, false);
xhttp.send("");
return xhttp.responseXML;
}
function loadXMLDoc(dname) {
if (window.ActiveXObject) {
return loadXMLDocActiveX(dname);
}
else if (window.XMLHttpRequest) {
return loadXMLDocOther(dname);
}
}
function transformActiveX(xml, xsl, target, selected) {
var transform = new ActiveXObject("MSXML2.XSLTemplate");
transform.stylesheet = xsl;
var processor = transform.createProcessor();
processor.input = xml;
if (selected) {
processor.addParameter("selected", selected);
}
processor.transform();
target.innerHTML = processor.output;
}
function transformOther(xml, xsl, target, selected) {
var xsltProcessor = new XSLTProcessor();
xsltProcessor.importStylesheet(xsl);
if (selected) {
xsltProcessor.setParameter(null, "selected", selected);
}
var resultDocument = xsltProcessor.transformToFragment(xml, document);
target.innerHTML = "";
target.appendChild(resultDocument);
}
function displayResult(selected) {
var targetElement = document.getElementById("load");
// code for IE
if (window.ActiveXObject) {
transformActiveX(xml, xsl, targetElement, selected);
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation &&
document.implementation.createDocument) {
transformOther(xml, xsl, targetElement, selected);
}
}
</script>
</head>
<body onload="displayResult()">
<div id="load">
</div>
</body>
</html>
私はツリーを作成するためにこのコードを使用しています今私はその中にxslが欲しいです
1)これを特定のノードから開始したい、たとえばここtest
でentity_id=1110
child
2)リーフ要素には、たとえばここのような1つのクラスがあります。リーフ要素はtest1, test12, test123
、value=testおよびvalue=test0の要素の場合です。