本文概述
- 参数说明
- XSLT < xsl:apply-template> 元素示例
<
xsl:apply-template
select = Expression
mode = QName>
<
/xsl:apply-template>
参数说明
Index | Name | Description |
---|---|---|
1) | select | 它用于处理XPath表达式从所有节点及其子节点列表中选择的节点。 |
2) | mode | 它用于允许对由其限定名称指定的元素进行多次处理, 每次生成不同的结果。 |
employee.xml
<
?xml version = "1.0"?>
<
?xml-stylesheet type = "text/xsl" href = "http://www.srcmini.com/employee.xsl"?>
<
class>
<
employee id = "001">
<
firstname>
Aryan<
/firstname>
<
lastname>
Gupta<
/lastname>
<
nickname>
Raju<
/nickname>
<
salary>
30000<
/salary>
<
/employee>
<
employee id = "024">
<
firstname>
Sara<
/firstname>
<
lastname>
Khan<
/lastname>
<
nickname>
Zoya<
/nickname>
<
salary>
25000<
/salary>
<
/employee>
<
employee id = "056">
<
firstname>
Peter<
/firstname>
<
lastname>
Symon<
/lastname>
<
nickname>
John<
/nickname>
<
salary>
10000<
/salary>
<
/employee>
<
/class>
【XSLT xsl(apply-template元素)】员工.xsl
<
?xml version = "1.0" encoding = "UTF-8"?>
<
xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<
xsl:template match = "/">
<
html>
<
body>
<
h2>
Employees<
/h2>
<
xsl:apply-templates select = "class/employee" />
<
/body>
<
/html>
<
/xsl:template>
<
xsl:template match = "class/employee">
<
xsl:apply-templates select = "@id" />
<
xsl:apply-templates select = "firstname" />
<
xsl:apply-templates select = "lastname" />
<
xsl:apply-templates select = "nickname" />
<
xsl:apply-templates select = "salary" />
<
br />
<
/xsl:template>
<
xsl:template match = "@id">
<
span style = "font-size = 25px;
">
<
xsl:value-of select = "." />
<
/span>
<
br />
<
/xsl:template>
<
xsl:template match = "firstname">
First Name:<
span style = "color:brown;
">
<
xsl:value-of select = "." />
<
/span>
<
br />
<
/xsl:template>
<
xsl:template match = "lastname">
Last Name:<
span style = "color:green;
">
<
xsl:value-of select = "." />
<
/span>
<
br />
<
<
/xsl:template>
<
xsl:template match = "nickname">
Nick Name:<
span style = "color:blue;
">
<
xsl:value-of select = "." />
<
/span>
<
br />
<
/xsl:template>
<
xsl:template match = "salary">
Marks:<
span style = "color:red;
">
<
xsl:value-of select = "." />
<
/span>
<
br />
<
/xsl:template>
<
/xsl:stylesheet>
输出
文章图片
推荐阅读
- wap2app-- wap2app的原生标题头无法隐藏
- XPath轴介绍和示例
- XPath语法
- XPath相对路径
- XPath节点
- XPath表达式
- 什么是XPath
- XSLT xsl(message元素)
- XSLT xsl(import元素)