我是通过xml+xsl生成一个网页,我想通过click一个节点,就显示该节点下的值。例如:
<company>
<products>
<product> A </product>
<name> Aid </name>
<size> 8 </size>
</products>
<products>
<product> B </product>
<name> Boy </name>
<size> 10 </size> 数据挖掘研究院
</products>
</company>
现在显示出来的是product的名字Aid和Boy,通过如下代码:
<table>
<xsl:for-each select="company/products/name">
<tr> <td> <xsl:value-of select="."/> </td> </tr>
</xsl:for-each>
</table>
我想通过click这两个名字,在另一个table中显示详细的信息,比如我点击Aid,就显示Aid的详细信息,点击Boy,就显示Boy的详细信息,该怎么做?
下例是我写死了一个product来显示的,求大大帮忙转换成动态显示的吧
<table>
<xsl:for-each select="company/products/name">
<tr> <td> <xsl:value-of select="."/> </td> </tr>
</xsl:for-each>
</table>
<table>
<xsl:for-each select="company/products">
<xsl:if test="name='Aid'">
<tr> <td> <xsl:value-of select="."/> </td> </tr>
</xsl:if>
</xsl:for-each>
</table> 这个需要借助js脚本,请稍等,我写个例子给你.- XML code
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<company>
<products>
<product> A </product>
<name> Aid </name>
<size> 8 </size>
</products>
<products>
<product> B </product>
<name> Boy </name>
<size> 10 </size>
</products>
</company>
数据挖掘工具
test.xsl
- XML code
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<script type="text/javascript">
function fillTable(p,n,s)
{
var tdP = document.getElementById("tdP");
var tdN = document.getElementById("tdN");
var tdS = document.getElementById("tdS");
tdP.innerHTML = p;
tdN.innerHTML = n;
tdS.innerHTML = s;
var tbContainer = document.getElementById("tbContainer");
tbContainer.style.display="";
}
</script>
<table>
<xsl:for-each select="company/products/name">
<tr><td><a href="javascript:fillTable("{../product}","{../name}","{../size}")"><xsl:value-of
select="."/></a> </td> </tr>
</xsl:for-each>
</table>
<table>
<xsl:for-each select="company/products">
<xsl:if test="name="Aid"">
<tr> <td> <xsl:value-of select="."/> </td> </tr>
</xsl:if>
</xsl:for-each>
</table>
<table id="tbContainer" style="display:none" border="1">
<tr><td id="tdP"></td></tr>
<tr><td id="tdN"></td></tr>
<tr><td id="tdS"></td></tr>
</table>
</xsl:template>
</xsl:stylesheet>
我上面是写好表格,然后动态填充. 实际上,这个表格也可以是动态创建的.
另外,用数据岛的方式应该也是可以实现的,我就没有测试了.再补充一下数据岛方式的实现
- XML code
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<script type="text/javascript">
//老的那个利用dhtml方式实现的
/*function fillTable(p,n,s)
{
var tdP = document.getElementById("tdP");
var tdN = document.getElementById("tdN");
var tdS = document.getElementById("tdS");
tdP.innerHTML = p;
tdN.innerHTML = n;
tdS.innerHTML = s;
var tbContainer = document.getElementById("tbContainer");
tbContainer.style.display="";
}*/
//利用数据岛方式实现的
function moveMyItem(p)
{
myIsland.recordset.moveFirst();
myIsland.recordset.move(p-1);
}
</script>
<table>
<xsl:for-each select="company/products/name">
<tr>
<td>
<!--利用dhtml方式实现-->
<!--<a href="javascript:fillTable("{../product}","{../name}","{../size}")">-->
<!--利用数据岛方式实现-->
<a href="javascript:moveMyItem("{position()}")">
<xsl:value-of select="."/>
</a>
</td>
</tr>
</xsl:for-each>
</table>
<table>
<xsl:for-each select="company/products">
<tr>
<td>
<xsl:value-of select="."/>
</td>
</tr>
</xsl:for-each>
</table>
<xml id="myIsland" src="test.xml">
</xml>
<table id="tbContainer" border="1">
<tr><td id="tdP"></td></tr>
<tr><td id="tdN"></td></tr>
<tr><td id="tdS"></td></tr>
</table>
<table id="tbIsland">
<tr><td>a<span datasrc="#myIsland" datafld="product"></span></td></tr>
<tr><td>a<span datasrc="#myIsland" datafld="name"></span></td></tr>
<tr><td>a<span datasrc="#myIsland" datafld="size"></span></td></tr>
</table>
</xsl:template>
</xsl:stylesheet>
数据挖掘实验室
Create By Any-Extract(WL-AE)
数据挖掘实验室