菜鸟问题,在XSL中如何关闭一系列表,怎样修改变量值?
有许多表,表ID命名为“t{@COMPANYNAME}{position()}”
<table id = "t{@COMPANYNAME}{position()}" width="800" border="0" cellspacing="0" cellpadding="0" align="center">
现在想在另个表中关闭表名前部为“t{@COMPANYNAME} ”的表,我写了"<a herf = "#" onclick = "javascript:t{@COMPANYNAME}{*}.style.display = 'none'">Close</a>"但是,不行,问大侠应该怎么改?
<table id = "t{@COMPANYNAME}" width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<tr height="20">
<td cols="2"></td>
</tr>
<tr bgcolor="#6699FF">
<td colspan="2"><font color="#ffffff">COMPANY NAME:<xsl:value-of select="@COMPANYNAME" /></font></td>
</tr>
<tr bgcolor="#6699FF">
<td colspan="2"><a herf = "#" onclick = "javascript:t{@COMPANYNAME}{*}.style.display = 'none'"><font color="#0000FF">Close</font></a></td>
</tr>
</table>
问题点数:20、回复次数:13Top
1 楼lenoray()回复于 2004-12-27 10:15:40 得分 0
再问个问题,如果有个表放{@COMPANYNAME},里面有重复,但只想出现一个,怎么办?
<table width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<xsl:apply-templates select="SITE" >
</xsl:apply-templates>
</table>
<xsl:template match="SITE">
<tr bgcolor="#6699FF">
<td width="360"><font color="#ffffff">COMPANY NAME:<xsl:value-of select="@COMPANYNAME" /></font></td>
</tr>
</xsl:template>Top
2 楼lenoray()回复于 2004-12-27 12:05:22 得分 0
这是XML文件
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="xsl.xsl" ?>
<root>
<SITE COMPANYNAME="SMIC" IPURLSOU="172.28.20.40" IPURLDES="ftp.smics.com" NAMESOU="SMICa1" NAMEDES="SMICa1" PATHSOU="/export/home/asx/0228x-10/0163D/h02656" PATHDES="/CP/customer/0228/stdf/h02656">
<ITEM STATE="Updated">
<NAME>m0265620.asc</NAME>
<SIZE>3190</SIZE>
<MODETIME>2004-12-23 20:23:00</MODETIME>
<UPDATETIME>2004-12-24 14:01:56</UPDATETIME>
</ITEM>
</SITE>
<SITE COMPANYNAME="SMIC" IPURLSOU="172.28.20.40" IPURLDES="ftp.smics.com" NAMESOU="SMICa1" NAMEDES="SMICa1" PATHSOU="/export/home/asx/0228x-10/0163D/h02656" PATHDES="/CP/customer/0228/stdf/h02656">
<ITEM STATE="Updated">
<NAME>m0265606.asc</NAME>
<SIZE>3190</SIZE>
<MODETIME>2004-12-23 19:44:00</MODETIME>
<UPDATETIME>2004-12-24 14:02:08</UPDATETIME>
</ITEM>
</SITE>
<SITE COMPANYNAME="ZMIC" IPURLSOU="172.28.20.43" IPURLDES="ftp.smics.com" NAMESOU="SMICa2" NAMEDES="SMICa2" PATHSOU="/export/home/asx/0228x-10/0163D/h02530" PATHDES="/CP/customer/0228/stdf/h02530">
<ITEM STATE="Updated">
<NAME>z0253025.asc</NAME>
<SIZE>1978</SIZE>
<MODETIME>2004-12-17 17:37:00</MODETIME>
<UPDATETIME>2004-12-24 14:02:00</UPDATETIME>
</ITEM>
</SITE>
<SITE COMPANYNAME="local" IPURLSOU="172.28.20.46" IPURLDES="172.28.20.11" NAMESOU="1224a2" NAMEDES="1224a2" PATHSOU="/export/home/asx/0228x-10/repair_data" PATHDES="/export/home1/SE3/repair_data">
<ITEM STATE="Updated">
<NAME>l-h02656-25.asc</NAME>
<SIZE>105859</SIZE>
<MODETIME>2004-12-22 19:43:00</MODETIME>
<UPDATETIME>2004-12-24 14:08:24</UPDATETIME>
</SITE>
<SITE COMPANYNAME="local" IPURLSOU="172.28.20.40" IPURLDES="172.28.20.11" NAMESOU="1224a1" NAMEDES="1224a1" PATHSOU="/export/home/asx/0228x-10/repair_data" PATHDES="/export/home1/SE3/repair_data">
<ITEM STATE="Updated">
<NAME>l-h02529-25.asc</NAME>
<SIZE>121203</SIZE>
<MODETIME>2004-12-23 18:41:00</MODETIME>
<UPDATETIME>2004-12-24 14:08:24</UPDATETIME>
</ITEM>
</SITE>
</root>Top
3 楼Gavin(天行健,君子以自强不息)回复于 2004-12-27 14:08:11 得分 20
暂时没有好办法.
1.用document.getElementsByTagName("table"),然后判断id的是否startWith你那个companyname,然后再设置visible.
2.在SITE那个template里面,加一个判断position()=1,才显示,就可以只显示一次Top
4 楼lenoray()回复于 2004-12-27 14:31:10 得分 0
多谢啊
现在想做的是把那个XML改成按公司名显示,已开始只显示公司名和公司名下面的DETAIL,CLOSE
按DETAIL后才显示这个公司的任务(因为有好几个公司,每个公司有好几个任务,任务顺序不定)
苦于没有想法,缺乏XSLT的思想方法
现在只能做到上次的程度,晕啊
Top
5 楼lenoray()回复于 2004-12-27 14:31:33 得分 0
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="html" />
<xsl:param name = "cpname" select = "*" />
<xsl:template match="/root">
<html>
<head>
<title>Update Files Log</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<xsl:apply-templates select="SITE" >
<xsl:sort select = "@COMPANYNAME" order = "ascending"/>
</xsl:apply-templates>
<br />
<br />
</body>
</html>
</xsl:template>
<xsl:template match="SITE">
<table id = "t{@COMPANYNAME}{position()}" width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<tr height="20">
<td cols="2"></td>
</tr>
<tr bgcolor="#6699FF">
<td colspan="2"><font color="#ffffff">COMPANY NAME:<xsl:value-of select="@COMPANYNAME" /></font></td>
</tr>
<tr height="1">
<td cols="2"></td>
</tr>
<tr bgcolor="#6699FF">
<td width="160"><font color="#ffffff">Source Server:</font></td>
<td width="640" bgcolor="#EBEBEB"> <xsl:value-of select="@NAMESOU" /><xsl:if test="@IPURLSOU != ''">(<xsl:value-of select="@IPURLSOU" />)</xsl:if></td>
</tr>
<tr bgcolor="#6699FF">
<td width="160"><font color="#ffffff">Source Path:</font></td>
<td width="640" bgcolor="#EBEBEB"> <xsl:value-of select="@PATHSOU" /></td>
</tr>
<tr bgcolor="#6699FF">
<td width="160"><font color="#ffffff">Target Server:</font></td>
<td width="640" bgcolor="#EBEBEB"> <xsl:value-of select="@NAMEDES" /><xsl:if test="@IPURLDES != ''">(<xsl:value-of select="@IPURLDES" />)</xsl:if></td>
</tr>
<tr bgcolor="#6699FF">
<td width="160"><font color="#ffffff">Target Path:</font></td>
<td width="640" bgcolor="#EBEBEB"><xsl:value-of select="@PATHDES" /></td>
</tr>
<tr bgcolor="#6699FF">
<td width="160"><font color="#ffffff">Updated Files/Total Files:</font></td>
<td width="640" bgcolor="#EBEBEB"><xsl:value-of select="count(ITEM[@STATE!='DownErr' and @STATE!='UpdateErr'])" />/<xsl:value-of select="count(ITEM)" /></td>
</tr>
<tr bgcolor="#6699FF">
<td width="160"><font color="#ffffff">Transfer error:</font></td>
<td width="640" bgcolor="#EBEBEB"><xsl:value-of select="count(ITEM) - count(ITEM[@STATE!='DownErr' and @STATE!='UpdateErr']) " /></td>
</tr>
<tr bgcolor="#6699FF">
<td width="160"><font color="#ffffff">Updated Size/Total Size</font></td>
<td width="640" bgcolor="#EBEBEB"><xsl:value-of select="sum(ITEM[@STATE!='DownErr' and @STATE!='UpdateErr']/SIZE)" />/<xsl:value-of select="sum(ITEM/SIZE)" /></td>
</tr>
<tr bgcolor="#EBEBEB">
<td width="160"><a herf = "#" onclick = "javascript:t{position()}.style.display = ''"><font color="#0000FF">Detail</font></a> </td>
<td width="640"><a herf = "#" onclick = "javascript:t{position()}.style.display = 'none'"><font color="#0000FF">Close</font></a></td>
</tr>
<tr height="3">
<td cols="2"></td>
</tr>
</table>
<table id = "t{position()}" style='display:none' width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="#6699FF">
<td width="300"><font color="#ffffff">File Name</font></td>
<td width="100"><font color="#ffffff">File Size</font></td>
<td width="200"><font color="#ffffff">Last Modify Time</font></td>
<td width="200"><font color="#ffffff">Update Time</font></td>
</tr>
<xsl:apply-templates select="ITEM">
</xsl:apply-templates>
</table>
</xsl:template>
<xsl:template match="ITEM">
<tr>
<xsl:attribute name="bgcolor">
<xsl:choose>
<xsl:when test="@STATE='Updated'">#ebebeb</xsl:when>
<xsl:when test="@STATE='DownErr'">#ff9999</xsl:when>
<xsl:when test="@STATE='UpdateErr'">#ff9999</xsl:when>
<xsl:otherwise>#ebebeb</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<td width="300"><xsl:value-of select="NAME" /></td>
<td width="100"><xsl:value-of select="SIZE" /></td>
<td width="200"><xsl:value-of select="MODETIME" /></td>
<td width="200"><xsl:value-of select="UPDATETIME" /></td>
</tr>
</xsl:template>
</xsl:stylesheet>Top
6 楼Gavin(天行健,君子以自强不息)回复于 2004-12-27 14:50:30 得分 0
try:
<xsl:key name="getUnitCompany" match="SITE" use="@COMPANYNAME"/>
....
<!-- 得到有多少个site,如纪录有SIMC,local,SIMC,local,ZMIC,ZMIC,则,返回 SIMC,local,ZMIC ,当然,你自己可以sort-->
<xsl:for-each select="SITE[generate-id(.)=generate-id(key('getUnitCompany',@COMPANYNAME))]">
<xsl:variable name="curSITE" select="@COMPANYNAME"/>
<!-- 取出同名的SITE的数据-->
<xsl:for-each select="SITE[@COMPANYNAME=$curSITE]">
<!-- do what u want -->
</xsl:for-each>
</xsl:for-each>
Top
7 楼lenoray()回复于 2004-12-27 15:17:13 得分 0
怎么出现
无法解决关键字 'getUnitCompany' 的引用。xsl:key 指令必须声明在样式表顶层。
怎么办?Top
8 楼Gavin(天行健,君子以自强不息)回复于 2004-12-27 15:24:25 得分 0
1。key的声明要放到template外面
2。 这个可能有问题
<!-- 取出同名的SITE的数据-->
<xsl:for-each select="SITE[@COMPANYNAME=$curSITE]">
--〉
<!-- 取出同名的SITE的数据-->
<xsl:for-each select="/root/SITE[@COMPANYNAME=$curSITE]">
just For Test:<xsl:value-of select="ITEM/NAME"/>
Top
9 楼lenoray()回复于 2004-12-27 16:12:29 得分 0
好像,还是不行,
用<xsl:for-each select="SITE[@COMPANYNAME=$curSITE]">就什么都不显示了
而用<xsl:for-each select="/root/SITE[@COMPANYNAME=$curSITE]">后,重复的也显示了
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" method="html" />
<xsl:key name = "getUnitCompany" match = "SITE" use = "@COMPANYNAME" />
<xsl:template match="/root">
<html>
<head>
<title>Update Files Log</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table id = "t{@COMPANYNAME}" width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<xsl:for-each select="SITE[generate-id(.)=generate-id(key('getUnitCompany',@COMPANYNAME))]">
<xsl:variable name="curSITE" select="@COMPANYNAME"/>
<!-- 取出同名的SITE的数据-->
<xsl:for-each select="/root/SITE[@COMPANYNAME=$curSITE]">
<tr bgcolor="#6699FF">
<td colspan="2"><font color="#ffffff">COMPANY NAME:<xsl:value-of select="@COMPANYNAME" /></font></td>
</tr>
<!-- do what u want -->
</xsl:for-each>
</xsl:for-each>
</table>
<xsl:apply-templates select="SITE" >
<xsl:sort select = "@COMPANYNAME" order = "ascending"/>
</xsl:apply-templates>
<br />
<br />
</body>
</html>
</xsl:template>
Top
10 楼Gavin(天行健,君子以自强不息)回复于 2004-12-27 16:18:35 得分 0
在
<xsl:for-each select="SITE[generate-id(.)=generate-id(key('getUnitCompany',@COMPANYNAME))]">
这重循环,你仅需要构建你的site的主表信息
在
<xsl:for-each select="/root/SITE[@COMPANYNAME=$curSITE]">
这重循环,你需要构建detail的信息。
所以你应该将
COMPANY NAME:<xsl:value-of ..那段提到外层循环....
Good luckTop
11 楼lenoray()回复于 2004-12-27 16:44:50 得分 0
放到外层,只显示一次了,但是内层应该放什么呢?
Top
12 楼Gavin(天行健,君子以自强不息)回复于 2004-12-27 16:56:45 得分 0
...
放你处理
<ITEM STATE="Updated">
<NAME>m0265606.asc</NAME>
<SIZE>3190</SIZE>
<MODETIME>2004-12-23 19:44:00</MODETIME>
<UPDATETIME>2004-12-24 14:02:08</UPDATETIME>
</ITEM>
item信息的代码~~~Top
13 楼lenoray()回复于 2004-12-27 17:01:33 得分 0
....SORRY啊,我实在是没有思想.....
先送分,回家再发贴问,谢谢Gavin(天行健,君子以自强不息) 了1!Top





