欢迎大家光临【无师自通-教程网】您的到来是我们的荣幸。本站提供photoshop教程,ps教程,flash教程,cad教程,网页制作教程,excel教程,asp教程,vb教程,3d教程,c语言教程,html教程,coreldraw教程,dreamweaver教程,java教程,3dmax教程 等各种教程为主题的内容和服务,相信您会在这里找到您所需要的东东。无师自通伴您一生-谢谢您的光临!!
网站地图 设为首页
简繁切换 加入收藏
栏目待定 留言本站
您现在的位置: 无师自通-教程网 >> WEB开发 >> XML教程 >> XML基础教程 >> 教程正文

  没有公告

教程: XSL简明教程(7)XSL的控制语句 更多...
教程: XSL简明教程(7)XSL的控制语句
七. XSL 的控制语句

1.条件语句if...then

XSL同样还有条件语句(呵呵~~好厉害吧,象程序语言一样)。具体的语法是增加一个xsl:if元素,类似这样

<xsl:if match=".[ARTIST='Bob Dylan']">

... some output ...

</xsl:if>


上面的例子改写成为:

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">

<html>

<body>

<table border="2" bgcolor="yellow">

<tr>

<th>Title</th>

<th>Artist</th>

</tr>

<xsl:for-each select="CATALOG/CD">

<xsl:if match=".[ARTIST='Bob Dylan']">

<tr>

<td><xsl:value-of select="TITLE"/></td>

<td><xsl:value-of select="ARTIST"/></td>

</tr>

</xsl:if>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>


2. XSL 的Choose

choose的用途是出现多个条件,给出不同显示结果。具体的语法是增加一组xsl:choose,xsl:when,xsl:otherwise元素:


<xsl:choose>

<xsl:when match=".[ARTIST='Bob Dylan']">

... some code ...

</xsl:when>

<xsl:otherwise>

... some code ....

</xsl:otherwise>

</xsl:choose>


上面的例子改写成为:

<?xml version='1.0'?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

<xsl:template match="/">

<html>

<body>

<table border="2" bgcolor="yellow">

<tr>

<th>Title</th>

<th>Artist</th>

</tr>

<xsl:for-each select="CATALOG/CD">

<tr>

<td><xsl:value-of select="TITLE"/></td>

<xsl:choose>

<xsl:when match=".[ARTIST='Bob Dylan']">

<td bgcolor="#ff0000"><xsl:value-of select="ARTIST"/></td>

</xsl:when>

<xsl:otherwise>

<td><xsl:value-of select="ARTIST"/></td>

</xsl:otherwise>

</xsl:choose>

</tr>

</xsl:for-each>

</table>

</body>

</html>

</xsl:template>

</xsl:stylesheet>


教程录入:admin    责任编辑:admin 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     
     
     
     

    asp连接mysql数据库

    asp连接mysql数据库-2

    frontpage2000教程---制作主页
    免责声明!本站资料大部分来自于互联网,其版权归原作者或其他合法者所有.如内容涉及或侵犯了您的权益,请通知本人,我将尽快处理!.欢迎您的光临。
    辽ICP备07003958号
    无师自通,伴你一生-教程网