<xsl:value-of>元素是选择当前节点的值,用于在结果树中创建一个文本节点。例如<xsl:value-of select="Name" />就是选择Name节点的值。
select属性是必须的,用于指定要计算的表达式,表达式计算的结果将被转换为一个字符串值。如果字符串为空,那么文本节点将不会被创建。
<xsl:for-each>元素逐个(select)选择某条件,应用条件。select属性是必须的,用于指定一个表达式,该表达式计算结果必须是一个节点集。<xsl:for-each>元素的内容是一个模板,对于每一个被选择的节点,实例化该模板。
<?xml-stylesheet type="text/xsl" href="src/employees44.xsl"?>
<employees>
<employee sn="E-200402100001">
<name>zhangsan</name>
<age>25</age>
<monthly_pay mode="cash">
1200.00
</monthly_pay>
</employee>
<employee sn="E-200402100006">
<name>lisi</name>
<age>28</age>
<monthly_pay mode="cash">
1600.00
</monthly_pay>
</employee>
<employee sn="E-200503220001">
<name>wangwu</name>
<age>30</age>
<monthly_pay mode="credit_card">
3500.00
</monthly_pay>
</employee>
</employees>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head></head>
<xsl:apply-templates/>
</html>
</xsl:template>
<xsl:template match="employees">
<body>
<table border="1">
<xsl:for-each select="employee">
<tr>
<td><xsl:value-of select="name"/></td>
<td><xsl:value-of select="age"/></td>
<td><xsl:value-of select="monthly_pay"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</xsl:template>
</xsl:stylesheet>
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<table border="1">
<tr>
<td>zhangsan</td>
<td>25</td>
<td>1200.00</td>
</tr>
<tr>
<td>lisi</td>
<td>28</td>
<td>1600.00</td>
</tr>
<tr>
<td>wangwu</td>
<td>30</td>
<td>3500.00</td>
</tr>
</table>
</body>
</html>
leizhimin 博主 2008-11-19
lulei0320 2008-11-19
huigo1234 2008-01-23
huigo1234 2008-01-23