data.xml文件:
1<root>
2<commodity id="1205">
3<name>橡皮</name>
4<price unit="元">0.3</price>
5</commodity>
6<commodity id="1206">
7<name>铅笔</name>
8<price unit="元">1</price>
9</commodity>
10</root>
data.htm文件:
1<table border="1" width="100%">
2<tr><td>1</td><td>墨水</td><td>4.0元</td>
3<td width="10%"><a href="aa.asp?id=1205">修改</a></td><td width="10%"><a href="aa.asp?id=1205">删除</a></td>
4</tr>
5<tr><td>2</td><td>钢笔</td><td>30元</td>
6<td width="10%"><a href="aa.asp?id=1206">修改</a></td><td><a href="aa.asp?id=1205">删除</a></td>
7</tr>
8</table>
此xsl也可用于其他类似的xml的显示转换比如:
data1.xml文件:
1<root>
2<user id="12">
3<name>张静</name>
4<age unit="岁">23</age>
5</user>
6<user id="13">
7<name>王启远</name>
8<age unit="岁">31</age>
9</user>
10</root>
---------------------------------------------------------------
1<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2<xsl:template match="/">
3<table border="1" id="Table1" width="100%">
4<xsl:apply-templates mode="First" select="*"></xsl:apply-templates>
5</table>
6</xsl:template>
7<xsl:template match="*" mode="First">
8<tr>
9<td>
10<xsl:value-of select="position()"></xsl:value-of>
11</td>
12<xsl:apply-templates mode="Second" select="*"></xsl:apply-templates>
13<td width="10%">
14<a href="aa.asp?id={@id}">修改</a>
15</td>
16<td width="10%">
17<a href="aa.asp?id={@id}">删除</a>
18</td>
19</tr>
20</xsl:template>
21<xsl:template match="*" mode="Second">
22<td>
23<xsl:value-of select="."></xsl:value-of>
24<xsl:if test="@unit">
25<xsl:value-of select="@unit"></xsl:value-of>
26</xsl:if>
27</td>
28</xsl:template>
29</xsl:stylesheet>