象CSDN的帖子列表页面那样,一行是蓝的,一行是白的如何实现的? 用CSS来做或许可以,但为什么用单行双行来判断不算呢?不同意你所说的效率不高的说法 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 css:.p1{.....};.p2{.....};JSP:<%int k = 0;for(.....){%><a href="1.html" class="p<%=(1-k)%>">OK</a><%}%>应该没有比这再高效的了. 更正:css:.p0{.....};.p1{.....}; 靠,再更正:JSP:<%int k = 0;for(.....){k=1-k;%><a href="1.html" class="p<%=k%>">OK</a><%}%> to xiaofenguser(风雨)比我的简单,严重同意! 对于这个页面,大家看清楚人家ISDN可是用XML + XSL实现的!多学学这个! 更正,写错了:对于这个页面,大家看清楚人家CSDN可是用XML + XSL实现的!多学学这个! xml+xsl原理于是一样的。看看吧。 <?xml version="1.0" encoding="gb2312" ?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" > <xsl:import href="page.xsl"/><xsl:template match="/"> <xsl:variable name="sorted.items"> <xsl:call-template name="page.filter"> <xsl:with-param name="dataset" select="//Topics/Topic"/> <xsl:with-param name="page" select="1"/> <xsl:with-param name="page.size" select="30"/> </xsl:call-template> </xsl:variable> <xsl:for-each select="msxsl:node-set($sorted.items)/*"> <xsl:choose> <xsl:when test="position() mod 2 = 0"> <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff"> <tr height="22"> <td class="WithBreaks"> <xsl:choose> <xsl:when test="endstate=0"> <xsl:choose> <xsl:when test="Point>0"> <b><font color="green">?</font></b> </xsl:when> <xsl:otherwise> <font color="darkgray" face="Wingdings">r</font> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:when test="endstate=1"> <b><font color="green">√</font></b> </xsl:when> <xsl:when test="endstate=2"> <b><font color="red">√</font></b> </xsl:when> <xsl:otherwise>    </xsl:otherwise> </xsl:choose> <xsl:element name="a"> <xsl:attribute name="href">/Expert/TopicView1.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute> <xsl:attribute name="target">_blank</xsl:attribute> <xsl:value-of select="TopicName"/> </xsl:element> (<xsl:value-of select="PostUserName"/> ) </td> <td width="30" align="right"> <xsl:apply-templates select="Point" /> </td> <td width="30" align="right"> <xsl:apply-templates select="ReplyNum" /> </td> <td width="80" align="right"> <xsl:apply-templates select="ReplyDateTime" /> </td> <td width="30" align="right"> <xsl:element name="a"> <xsl:attribute name="href">/Expert/TopicView2.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute> <xsl:attribute name="target">_blank</xsl:attribute> 管理 </xsl:element> </td> </tr> </table> </xsl:when> <xsl:otherwise> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="color5"> <tr height="22"> <td class="WithBreaks"> <xsl:choose> <xsl:when test="endstate=0"> <xsl:choose> <xsl:when test="Point>0"> <b><font color="green">?</font></b> </xsl:when> <xsl:otherwise> <font color="darkgray" face="Wingdings">r</font> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:when test="endstate=1"> <b><font color="green">√</font></b> </xsl:when> <xsl:when test="endstate=2"> <b><font color="red">√</font></b> </xsl:when> <xsl:otherwise>    </xsl:otherwise> </xsl:choose> <xsl:element name="a"> <xsl:attribute name="href">/Expert/TopicView1.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute> <xsl:attribute name="target">_blank</xsl:attribute> <xsl:value-of select="TopicName"/> </xsl:element> (<xsl:value-of select="PostUserName"/> ) </td> <td width="30" align="right"> <xsl:apply-templates select="Point" /> </td> <td width="30" align="right"> <xsl:apply-templates select="ReplyNum" /> </td> <td width="80" align="right"> <xsl:apply-templates select="ReplyDateTime" /> </td> <td width="30" align="right"> <xsl:element name="a"> <xsl:attribute name="href">/Expert/TopicView2.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute> <xsl:attribute name="target">_blank</xsl:attribute> 管理 </xsl:element> </td> </tr> </table> </xsl:otherwise> </xsl:choose> </xsl:for-each></xsl:template><xsl:template match="ReplyDateTime"> <xsl:value-of select="substring-before(substring-after(., '-'), ' ')"/>  <xsl:value-of select="substring-before(substring-after(., ' '),':')"/>: <xsl:value-of select="substring-before(substring-after(.,':'),':')"/></xsl:template></xsl:stylesheet> 楼上的说得有道理,但是:XSL模板只要写好一次,所有的xml文件套用就可以了。编程人员只关心xml怎么生成,样式就不需要关心了。 我演示一个例子:更简单------------------------------------file:lines.xml------------------------------------<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="lines.xsl"?><doc> <line>Bravery</line> <line>Endurant</line> <line>Aggressive</line> <line>Strong</line> <line>Tolerant</line></doc>------------------------------------file:lines.xsl------------------------------------<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="doc"> <html> <head> <title></title> <style type="text/css"> tr.blueTR{ background-color:blue; } tr.redTR{ background-color:red; } </style> </head> <body> <table> <xsl:apply-templates select="line"/> </table> </body> </html> </xsl:template> <xsl:template match="line[position() mod 2 = 0]"> <tr class="redTR"> <td><xsl:value-of select="."/></td> </tr> </xsl:template> <xsl:template match="line[position() mod 2 = 1]"> <tr class="blueTR"> <td><xsl:value-of select="."/></td> </tr> </xsl:template> </xsl:stylesheet>-----------------------------------file:lines.htm(生成的结果)-----------------------------------<html xmlns:fo="http://www.w3.org/1999/XSL/Format"><head><title></title><style type="text/css"> tr.blueTR{ background-color:blue; } tr.redTR{ background-color:red; } </style></head><body><table><tr class="blueTR"><td>Bravery</td></tr><tr class="redTR"><td>Endurant</td></tr><tr class="blueTR"><td>Aggressive</td></tr><tr class="redTR"><td>Strong</td></tr><tr class="blueTR"><td>Tolerant</td></tr></table></body></html> 编程人员这需要关心这个文档,不像直接用css循环控制,程序员要手动判断奇数行,偶数行<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="lines.xsl"?><doc> <line>Bravery</line> <line>Endurant</line> <line>Aggressive</line> <line>Strong</line> <line>Tolerant</line></doc>生成样式的工作(这里是红蓝交替的行)全部交给xsl来完成。这就是xml将内容和样式分开的大义所在! 呵,别人关心的不是xsl分行显示.别人要水,你难道给他汽油么? 大家好我刚学习jsp但是在.net里面这个问题可以做模版解决难道jsp里面不可以么? archangelye(叶)呵,给你开玩笑的,以后还要向你多请教XSL里面的东西.我在XSL里有好多东西都一知半解 xiaofenguser(风雨)没关系!我们从彼此身上学到东西,得到启发,这是最重要的!<%int k = 0;for(.....){k=1-k;%>你的这段程序就很妙,换了我肯定写成<%int k = 0;for(.....){k++;if(0 == k%2)...else...}%> 用css,xml实现其实都是好方法,学习啊! <%int k = 0;for(.....){k=1-k;%>聪明啊…… 直接通过javascript动态生成表格不就行轻啦!! 求助!! 关于JSP文件上传导致的乱码问题 SSH页面请求不进后台 急.. 如何在循环中获取radio的值........急用 jsp中使用javaBeans的问题(走头无路首次提问,各位老师帮帮我) 用JSP打开的PDF文档怎么才能防止别人另存为? jsp怎样实现双列分页呢?高手指点 关于jsp页面跳转和list列表翻页得问题高分啊(100) 新手:404 如何从表单调用servlet? 使用 request.getRequestDispatcher的问题 如何访问自己的JSP? 100分,如何安装sturts?解决马上送分
.p1{.....};
.p2{.....};JSP:
<%
int k = 0;
for(.....){%><a href="1.html" class="p<%=(1-k)%>">OK</a>
<%
}
%>应该没有比这再高效的了.
css:
.p0{.....};
.p1{.....};
JSP:
<%
int k = 0;
for(.....){
k=1-k;
%>
<a href="1.html" class="p<%=k%>">OK</a>
<%
}
%>
比我的简单,严重同意!
多学学这个!
对于这个页面,大家看清楚人家CSDN可是用XML + XSL实现的!
多学学这个!
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
version="1.0" >
<xsl:import href="page.xsl"/>
<xsl:template match="/">
<xsl:variable name="sorted.items">
<xsl:call-template name="page.filter">
<xsl:with-param name="dataset" select="//Topics/Topic"/>
<xsl:with-param name="page" select="1"/>
<xsl:with-param name="page.size" select="30"/>
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="msxsl:node-set($sorted.items)/*">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#ffffff">
<tr height="22">
<td class="WithBreaks">
<xsl:choose>
<xsl:when test="endstate=0">
<xsl:choose>
<xsl:when test="Point>0">
<b><font color="green">?</font></b>
</xsl:when>
<xsl:otherwise>
<font color="darkgray" face="Wingdings">r</font>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="endstate=1">
<b><font color="green">√</font></b>
</xsl:when>
<xsl:when test="endstate=2">
<b><font color="red">√</font></b>
</xsl:when>
<xsl:otherwise>
  
</xsl:otherwise>
</xsl:choose>
<xsl:element name="a">
<xsl:attribute name="href">/Expert/TopicView1.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="TopicName"/>
</xsl:element>
(<xsl:value-of select="PostUserName"/> )
</td>
<td width="30" align="right">
<xsl:apply-templates select="Point" />
</td>
<td width="30" align="right">
<xsl:apply-templates select="ReplyNum" />
</td>
<td width="80" align="right">
<xsl:apply-templates select="ReplyDateTime" />
</td>
<td width="30" align="right">
<xsl:element name="a">
<xsl:attribute name="href">/Expert/TopicView2.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
管理
</xsl:element>
</td>
</tr>
</table>
</xsl:when>
<xsl:otherwise>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="color5">
<tr height="22">
<td class="WithBreaks">
<xsl:choose>
<xsl:when test="endstate=0">
<xsl:choose>
<xsl:when test="Point>0">
<b><font color="green">?</font></b>
</xsl:when>
<xsl:otherwise>
<font color="darkgray" face="Wingdings">r</font>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="endstate=1">
<b><font color="green">√</font></b>
</xsl:when>
<xsl:when test="endstate=2">
<b><font color="red">√</font></b>
</xsl:when>
<xsl:otherwise>
  
</xsl:otherwise>
</xsl:choose>
<xsl:element name="a">
<xsl:attribute name="href">/Expert/TopicView1.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
<xsl:value-of select="TopicName"/>
</xsl:element>
(<xsl:value-of select="PostUserName"/> )
</td>
<td width="30" align="right">
<xsl:apply-templates select="Point" />
</td>
<td width="30" align="right">
<xsl:apply-templates select="ReplyNum" />
</td>
<td width="80" align="right">
<xsl:apply-templates select="ReplyDateTime" />
</td>
<td width="30" align="right">
<xsl:element name="a">
<xsl:attribute name="href">/Expert/TopicView2.asp?id=<xsl:value-of select="TopicId"/></xsl:attribute>
<xsl:attribute name="target">_blank</xsl:attribute>
管理
</xsl:element>
</td>
</tr>
</table>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template><xsl:template match="ReplyDateTime">
<xsl:value-of select="substring-before(substring-after(., '-'), ' ')"/> 
<xsl:value-of select="substring-before(substring-after(., ' '),':')"/>:
<xsl:value-of select="substring-before(substring-after(.,':'),':')"/>
</xsl:template>
</xsl:stylesheet>
XSL模板只要写好一次,所有的xml文件套用就可以了。
编程人员只关心xml怎么生成,样式就不需要关心了。
------------------------------------
file:lines.xml
------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="lines.xsl"?>
<doc>
<line>Bravery</line>
<line>Endurant</line>
<line>Aggressive</line>
<line>Strong</line>
<line>Tolerant</line>
</doc>
------------------------------------
file:lines.xsl
------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:template match="doc">
<html>
<head>
<title></title>
<style type="text/css">
tr.blueTR{
background-color:blue;
}
tr.redTR{
background-color:red;
}
</style>
</head>
<body>
<table>
<xsl:apply-templates select="line"/>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="line[position() mod 2 = 0]">
<tr class="redTR">
<td><xsl:value-of select="."/></td>
</tr>
</xsl:template>
<xsl:template match="line[position() mod 2 = 1]">
<tr class="blueTR">
<td><xsl:value-of select="."/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
-----------------------------------
file:lines.htm(生成的结果)
-----------------------------------
<html xmlns:fo="http://www.w3.org/1999/XSL/Format">
<head>
<title>
</title>
<style type="text/css">
tr.blueTR{
background-color:blue;
}
tr.redTR{
background-color:red;
}
</style>
</head>
<body>
<table>
<tr class="blueTR">
<td>Bravery</td>
</tr>
<tr class="redTR">
<td>Endurant</td>
</tr>
<tr class="blueTR">
<td>Aggressive</td>
</tr>
<tr class="redTR">
<td>Strong</td>
</tr>
<tr class="blueTR">
<td>Tolerant</td>
</tr>
</table>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="lines.xsl"?>
<doc>
<line>Bravery</line>
<line>Endurant</line>
<line>Aggressive</line>
<line>Strong</line>
<line>Tolerant</line>
</doc>
生成样式的工作(这里是红蓝交替的行)全部交给xsl来完成。
这就是xml将内容和样式分开的大义所在!
呵,给你开玩笑的,以后还要向你多请教XSL里面的东西.
我在XSL里有好多东西都一知半解
没关系!我们从彼此身上学到东西,得到启发,这是最重要的!
<%
int k = 0;
for(.....){
k=1-k;
%>
你的这段程序就很妙,换了我肯定写成
<%
int k = 0;
for(.....){
k++;
if(0 == k%2)
...
else
...
}
%>
int k = 0;
for(.....){
k=1-k;
%>
聪明啊……