XSLT与XML的应用,属性循环

XML数据:
1 <NewDataSet>
2 <theID>$theID</theID>
3        <tree href="/" style="border:1px">首 页</tree>
4        <tree href="/view.aspx">旅游景点</tree>
5         <tree href="/City.aspx">城市信息</tree>
6        <tree href="/line.aspx">旅游线路</tree>
7         <tree>旅游专题</tree>
8 </NewDataSet>

XSLT源码:
 1 <?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="topMenu.xml" -->
 2 <xsl:stylesheet version="1.0"
 3     xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xy" xmlns:xy="xytag">
 4     <xsl:param name="theID" select="NewDataSet/theID"/>
 5     <xsl:template match="/">
 6     <div class="menu">
 7     <span class="menu1"><img src="skin/images/menu1.jpg" /></span>
 8             <xsl:for-each select="NewDataSet/tree">
 9                 <xsl:choose>
10                     <xsl:when test="position()!=1">
11                     <span class="menu3"><img src="/skin/images/menu4.jpg" /></span>
12                     </xsl:when>
13                 </xsl:choose>
14                 <span>
15                     <xsl:choose>
16                         <xsl:when test="position()=$theID">
17                             <xsl:attribute name="class">menu22</xsl:attribute>
18                         </xsl:when>
19                         <xsl:otherwise>
20                             <xsl:attribute name="class">menu2</xsl:attribute>
21                             <xsl:attribute name="onmouseover">this.className='menu22'</xsl:attribute>
22                             <xsl:attribute name="onmouseout">this.className='menu2'</xsl:attribute>
23                         </xsl:otherwise>
24                     </xsl:choose>
25 
26                                 <a>
27                                     <xsl:attribute name="href">
28                                         <xsl:value-of select="@href"/>
29                                     </xsl:attribute>
30                                     <xsl:attribute name="title">
31                                         <xsl:value-of select="."/>
32                                     </xsl:attribute>
33                                     <xsl:for-each select="@*">
34                                      <xsl:if test="name() != 'href' and name() != 'title'">
35                                      <xsl:attribute name="{name()}">
36                                             <xsl:value-of select="."/>
37                                         </xsl:attribute>
38                                         </xsl:if>
39                                     </xsl:for-each>
40                                     <xsl:value-of select="."/>
41                                 </a>
42                 </span>
43             </xsl:for-each>
44       <span class="menu4"></span>
45       <span class="menu5"><img src="/skin/images/menu3.jpg" /></span>
46       </div>
47     </xsl:template>
48 </xsl:stylesheet>
49 
posted @ 2009-09-07 14:01  竹子小毅  阅读(224)  评论(0编辑  收藏  举报