本文概述
- 参数说明
- XSLT < xsl:key> 元素示例
<
xsl:key
name = QName
match = Pattern
use = Expression>
<
/xsl:key>
参数说明
Index | Name | Description |
---|---|---|
1) | Name | 它指定要使用的密钥的名称。 |
2) | Match | 它指定模式必须与拥有此键的节点匹配。 |
3) | Use | 它指定XPath表达式来标识xml文档节点的值。 |
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>
60000<
/salary>
<
/employee>
<
employee id = "024">
<
firstname>
Sonam<
/firstname>
<
lastname>
Gupta<
/lastname>
<
nickname>
Vinni<
/nickname>
<
salary>
45000<
/salary>
<
/employee>
<
employee id = "056">
<
firstname>
Peter<
/firstname>
<
lastname>
Symon<
/lastname>
<
nickname>
John<
/nickname>
<
salary>
20000<
/salary>
<
/employee>
<
/class>
员工.xsl
<
xsl:stylesheet version = "1.0"
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
<
xsl:key name = "firstname-search" match = "employee" use = "firstname"/>
<
xsl:template match = "/">
<
html>
<
body>
>
<
h2>
Employee<
/h2>
<
table border = "1">
<
tr bgcolor = "pink">
<
th>
ID<
/th>
<
th>
>
First Name<
/th>
<
th>
Last Name<
/th>
<
th>
Nick Name<
/th>
<
th>
Salary<
/th>
<
/tr>
>
<
xsl:for-each select = "key('firstname-search', 'Sonam')">
<
tr>
<
td>
<
xsl:value-of select = "@id"/>
<
/td>
<
td>
<
xsl:value-of select = "firstname"/>
<
/td>
<
td>
<
xsl:value-of select = "lastname"/>
>
<
/td>
<
td>
<
xsl:value-of select = "nickname"/>
<
/td>
<
td>
<
xsl:value-of select = "salary"/>
<
/td>
<
/tr>
<
/xsl:for-each>
<
/table>
<
/body>
<
/html>
<
/xsl:template>
<
/xsl:stylesheet>
【XSLT xsl(key元素)】输出
文章图片
推荐阅读
- XSLT xsl(import元素)
- poj 2385 Apple Catching(记录结果再利用的动态规划)
- react-native Android 全面屏手机 底部留有一大块黑屏
- 专题(“今日校园” App 用户体验分析)
- 社交电商模式商城APP开发分析
- 解决在Android设备播放音频与其他应用重音的问题,并监听耳机的控制按钮
- Mapper与Reducer浅析
- Android使用https与服务器交互的正确姿势
- Android-活动(Activity)Intent