本文概述
- 参数说明
- XSLT < xsl:if> 元素示例
<
xsl:if test="expression">
...some output if the expression is true...<
/xsl:if>
参数说明 测试:它指定要测试的xml数据中的条件。
XSLT < xsl:if> 元素示例 【XSLT xsl(if元素)】让我们举个例子, 通过遍历每位员工, 创建一个具有其属性” id” 及其子元素< firstname> , < lastname> , < nickname> 和< salary> 的元素表。让我们假设一个条件, 要求薪水大于15000, 然后打印员工的详细信息。
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>
员工.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>
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 = "class/employee">
<
xsl:if test = "salary >
30000">
<
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:if>
<
/xsl:for-each>
<
/table>
<
/body>
<
/html>
<
/xsl:template>
<
/xsl:stylesheet>
输出
文章图片
推荐阅读
- XQuery添加用法示例
- XSLT xsl(for-each元素)
- XSLT xsl:value-of用法
- XSLT语法用法示例
- XQuery正则表达式
- 什么是XSLT
- XQuery If Then Else语句
- Android学习—— Android studio的安装与配置
- Error:No toolchains found in the NDK toolchains folder for ABI with prefix: mips64el-linux-android(示