在XML文件里有两层数据,第二级数据默认样式为display:none,我想在点击第一层数据的时候以动态下拉的形式使第二层数据显示在页面上!(要求是存客户端脚本,可以在本地浏览,而不能用IIS等东西。)
下面是我的XML文件:
---------------------2.xml-----------------------------
1<laws xmlns:dt="urn:schemas-microsoft-com:datatypes">
2<law id="1" lb="《民法》">
3<slaw id="1">中华人民共和国民法通则11</slaw>
4<slaw id="2">中华人民共和国民法通则12</slaw>
5<slaw id="3">中华人民共和国民法通则13</slaw>
6</law>
7<law id="2" lb="《刑法》">
8<slaw id="1">中华人民共和国民法通则21</slaw>
9<slaw id="2">中华人民共和国民法通则22</slaw>
10<slaw id="3">中华人民共和国民法通则23</slaw>
11</law>
12<law id="3" lb="《合同法》">
13<slaw id="1">中华人民共和国民法通则31</slaw>
14<slaw id="2">中华人民共和国民法通则32</slaw>
15<slaw id="3">中华人民共和国民法通则33</slaw>
16<slaw id="4">中华人民共和国民法通则34</slaw>
17</law>
18</laws>
---------------------------end--------------------------------
下面为我的xsl样式表:
-------------------------2.xsl--------------------------------
1<xsl:stylesheet version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://mycompany.com/mynamespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2<xsl:template match="/">
3<html>
4<head>
5<link href="style.css" rel="stylesheet" type="text/css"/>
6</head>
7<body>
8<center>
9<table border="1" class="view" id="table1" width="95%">
10<xsl:for-each select="laws/law">
11<tr>
12<td class="td_head">
13<a onclick="javascript:shownr(this);" ta="ida"><xsl:value-of select="@lb"></xsl:value-of> ↓</a>
14</td>
15</tr>
16<xsl:for-each select="slaw">
17<xsl:variable name="sid" select="@id"></xsl:variable>
18<tr id="ida" style="display:none">
19<td class="td_bg1">
20<a onclick="shownr(this)" ta="xf"><font color="red">id:<xsl:value-of select="$sid"></xsl:value-of></font> ↓</a>
21</td>
22</tr>
23<tr name="xf" style="display:none">
24<td class="td_bg2">
25<font color="blue">小法</font>:<a href="{$sid}.xml"><xsl:value-of select="."></xsl:value-of></a>
26</td>
27</tr>
28<tr></tr>
29</xsl:for-each>
30</xsl:for-each>
31</table>
32</center>
33</body>
34<script language="JavaScript">
35<![CDATA[
36function shownr(obj){
37if(obj.ta != null){
38nt=document.all(obj.ta);
39alert(nt);
40if(nt.style.display=='none'){
41nt.style.display='block';
42obj.style.color='gray';
43}
44else{
45nt.style.display='none';
46obj.style.color='black';
47}
48}
49else
50return;
51}
52]]>
53</script>
54</html>
55</xsl:template>
56</xsl:stylesheet>
-------------------------------end-------------------------
请各位大侠快快帮忙,我在线等候,问题解决马上放分!!!
多谢各位!!!
---------------------------------------------------------------
1<xsl:stylesheet version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://mycompany.com/mynamespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2<xsl:template match="/">
3<script language="JavaScript"><![CDATA[
4function show(obj){
5if(obj.ta != null){
6nt=document.all(obj.ta);
7if(nt.style.display=='none'){
8nt.style.display='block';
9obj.style.color='gray';
10}
11else{
12nt.style.display='none';
13obj.style.color='black';
14}
15}
16else
17return;
18}
19]]></script>
20<table border="1">
21<xsl:for-each select="/laws/law">
22<tr>
23<td>
24<a href="#" onclick="show(this)" ta="ta{@id}">
25<xsl:value-of select="@lb"></xsl:value-of>
26</a>
27</td>
28</tr>
29<xsl:call-template name="a"></xsl:call-template>
30</xsl:for-each>
31</table>
32</xsl:template>
33<xsl:template name="a">
34<tr style="display:none">
35<xsl:attribute name="id">ta<xsl:value-of select="./@id"></xsl:value-of></xsl:attribute>
36<td>
37<xsl:for-each select="slaw">
38<xsl:value-of select="."></xsl:value-of>
39</xsl:for-each>
40</td>
41</tr>
42</xsl:template>
43</xsl:stylesheet>
---------------------------------------------------------------
1<xsl:stylesheet version="1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://mycompany.com/mynamespace" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2<xsl:template match="/">
3<html>
4<head>
5<link href="style.css" rel="stylesheet" type="text/css"/>
6</head>
7<body>
8<center>
9<table border="1" class="view" id="table1" width="95%">
10<xsl:for-each select="laws/law">
11<xsl:variable name="law" select="."></xsl:variable>
12<tr>
13<td class="td_head">
14<a onclick="javascript:shownr(this);" ta="ida{generate-id()}"><xsl:value-of select="@lb"></xsl:value-of> ↓</a>
15</td>
16</tr>
17<xsl:for-each select="slaw">
18<xsl:variable name="sid" select="@id"></xsl:variable>
19<tr id="ida{generate-id($law)}" style="display:none">
20<td class="td_bg1">
21<a onclick="shownr(this)" ta="xf"><font color="red">id:<xsl:value-of select="$sid"></xsl:value-of></font> ↓</a>
22</td>
23</tr>
24<tr name="xf" style="display:none">
25<td class="td_bg2">
26<font color="blue">小法</font>:<a href="{$sid}.xml"><xsl:value-of select="."></xsl:value-of></a>
27</td>
28</tr>
29<tr></tr>
30</xsl:for-each>
31</xsl:for-each>
32</table>
33</center>
34</body>
35<script language="JavaScript">
36<![CDATA[
37function shownr(obj){
38if(obj.ta != null){
39tas=document.all(obj.ta);
40for (var i=0; i < tas.length; i++)
41{
42nt = tas[i];
43if(nt.style.display=='none'){
44nt.style.display='block';
45obj.style.color='gray';
46}
47else
48{
49nt.style.display='none';
50obj.style.color='black';
51}
52}
53}
54else
55return;
56}
57]]>
58</script>
59</html>
60</xsl:template>
61</xsl:stylesheet>