码迷,mamicode.com
首页 > 其他好文 > 详细

如何控制XML文档的样式2

时间:2014-11-13 18:04:20      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   os   sp   for   

如何控制XML文档的样式1中研究了if过滤,其实xsl中还可以实现类似switch的效果,即<xsl:choose></xsl:choose>看下面的列子:

 1 <?xml version="1.0"?>
 2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 3 <xsl:template match="/">
 4     <html>
 5         <body>
 6             <h2>Team People Collection</h2>
 7             <table border="1">
 8                 <tr bgcolor="#9acd32">
 9                     <th align="left">Name</th>
10                     <th align="left">Gender</th>
11                 </tr>
12                 <xsl:for-each select="team/people">
13                     <xsl:sort select="name"/>
14                     <xsl:choose>
15                         <xsl:when test="name=‘zhangsan‘">
16                             <tr bgcolor="#ff00ff">
17                                 <td><xsl:value-of select="name"/></td>
18                                 <td><xsl:value-of select="gender"/></td>
19                             </tr>
20                         </xsl:when>
21                         <xsl:when test="name=‘maqi‘">
22                             <tr bgcolor="#cccccc">
23                                 <td><xsl:value-of select="name"/></td>
24                                 <td><xsl:value-of select="gender"/></td>
25                             </tr>
26                         </xsl:when>
27                         <xsl:otherwise>
28                             <tr>
29                                 <td><xsl:value-of select="name"/></td>
30                                 <td><xsl:value-of select="gender"/></td>
31                             </tr>
32                         </xsl:otherwise>
33                     </xsl:choose>
34                 </xsl:for-each>
35             </table>
36         </body>
37     </html>
38 </xsl:template>
39 </xsl:stylesheet>

高亮显示的代码即多分支选择的控制语句。

 

如何控制XML文档的样式2

标签:style   blog   http   io   color   ar   os   sp   for   

原文地址:http://www.cnblogs.com/qql1986/p/4087654.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!