1:Used XML and XSLT
-XML
2:Set in XML
Add the code below to XML doc
3:Use JavaScript
4:Use C#
Reference:http://msdn.microsoft.com/zh-cn/library/system.xml.xsl.xslcompiledtransform.transform.aspx
-XML
1
<?xml version="1.0" encoding="utf-8" ?>
2
<!--<?xml-stylesheet type="text/xsl" href="XSLTFile1.xslt"?>-->
3
4
<data>
5
<books>
6
<Name>SQL</Name>
7
<price>20.0</price>
8
</books>
9
<books>
10
<Name>CLR via C#</Name>
11
<price>120.0</price>
12
</books>
13
<books>
14
<Name>C#高级编程</Name>
15
<price>80.0</price>
16
</books>
17
<books>
18
<Name>C#级编程</Name>
19
<price>180.0</price>
20
</books>
21
<books>
22
<Name>C#编程</Name>
23
<price>60.0</price>
24
</books>
25
</data>
-XSLT2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
4
5
<xsl:output method="xml" indent="yes"/>
6
7
<xsl:template match="/">
8
<!--<xsl:copy>
9
<xsl:apply-templates select="@* | node()"/>
10
</xsl:copy>-->
11
<html>
12
<body>
13
<h2>My books to read:</h2>
14
<table border="1">
15
<tr bgcolor="green">
16
<th>Title</th>
17
<th>Price</th>
18
</tr>
19
<!--here we can use xpath to set conditions-->
20
<xsl:for-each select="data/books">
21
<xsl:sort select="Name" lang="zh-cn"/>
22
<!--also can set conditions here-->
23
<xsl:if test="price > 60">
24
<tr>
25
<td>
26
<xsl:value-of select="Name"/>
27
</td>
28
<td>
29
<xsl:value-of select="price"/>
30
</td>
31
</tr>
32
</xsl:if>
33
</xsl:for-each>
34
</table>
35
36
<h2>My books to read:</h2>
37
<table border="1">
38
<tr bgcolor="green">
39
<th>Title</th>
40
<th>Price</th>
41
</tr>
42
<xsl:for-each select="data/books">
43
<xsl:sort select="Name" lang="zh-cn"/>
44
<xsl:choose>
45
<xsl:when test="price > 60 and price < 100">
46
<tr>
47
<td>
48
<xsl:value-of select="Name"/>
49
</td>
50
<td >
51
<xsl:value-of select="price"/>
52
</td>
53
</tr>
54
</xsl:when>
55
<xsl:when test="price > 100">
56
<tr>
57
<td>
58
<xsl:value-of select="Name"/>
59
</td>
60
<td bgcolor="ff00ff">
61
<xsl:value-of select="price"/>
62
</td>
63
</tr>
64
</xsl:when>
65
<xsl:otherwise>
66
<tr>
67
<td>
68
<xsl:value-of select="Name"/>
69
</td>
70
<td bgcolor="#cccccc">
71
It's cheaper than $60
72
</td>
73
</tr>
74
</xsl:otherwise>
75
</xsl:choose>
76
</xsl:for-each>
77
</table>
78
79
<xsl:apply-templates></xsl:apply-templates>
80
81
</body>
82
</html>
83
</xsl:template>
84
85
<xsl:template match="data/books">
86
<p>
87
<xsl:apply-templates select="Name"/>
88
<xsl:apply-templates select="price"/>
89
</p>
90
</xsl:template>
91
92
<xsl:template match="Name">
93
Name: <span style="color:#ff0000">
94
<xsl:value-of select="."/>
95
</span>
96
<br />
97
</xsl:template>
98
99
<xsl:template match="price">
100
Price: <span style="color:#00ff00">
101
<xsl:value-of select="."/>
102
</span>
103
<br />
104
</xsl:template>
105
106
</xsl:stylesheet>
107
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
2:Set in XML
Add the code below to XML doc
1
<?xml-stylesheet type="text/xsl" href="XSLTFile1.xslt"?>
3:Use JavaScript
1
}
4:Use C#
1
protected void Page_Load(object sender, EventArgs e)
2
}
2
Reference:http://msdn.microsoft.com/zh-cn/library/system.xml.xsl.xslcompiledtransform.transform.aspx
字体是难看了点...不高兴调了~