- XPath 教程
- XPath - 主页
- XPath - 概述
- XPath - 表达式
- XPath - 节点
- XPath - 绝对路径
- XPath - 相对路径
- XPath - 轴
- XPath - 运算符
- XPath - 通配符
- XPath - 谓词
- XPath 有用资源
- XPath - 快速指南
- XPath - 有用资源
- XPath - 讨论
XPath - 布尔运算符
XPath 定义了以下布尔运算符,用于 XPath 表达式。
序号。 | 运算符 & 说明 |
---|---|
1 | and 两个条件都要满足 |
2 | or 满足任一条件即可 |
3 | not() 用于检查不满足条件的函数。 |
示例
本示例通过逐个迭代每个学生来创建一个表,其中包含 <student> 元素及其属性学号和子元素 <firstname>、<lastname><nickname> 和 <marks>。它检查学号为 393 或 493,然后打印学生的详细信息。
students.xml
<?xml version = "1.0"?> <?xml-stylesheet type = "text/xsl" href = "students.xsl"?> <class> <student rollno = "393"> <firstname>Dinkar</firstname> <lastname>Kad</lastname> <nickname>Dinkar</nickname> <marks>85</marks> </student> <student rollno = "493"> <firstname>Vaneet</firstname> <lastname>Gupta</lastname> <nickname>Vinni</nickname> <marks>95</marks> </student> <student rollno = "593"> <firstname>Jasvir</firstname> <lastname>Singh</lastname> <nickname>Jazz</nickname> <marks>90</marks> </student> </class>
students.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>Students</h2> <table border = "1"> <tr bgcolor = "#9acd32"> <th>Roll No</th> <th>First Name</th> <th>Last Name</th> <th>Nick Name</th> <th>Marks</th> </tr> <xsl:for-each select = "class/student[(@rollno = 393) or ((@rollno = 493))]"> <tr> <td><xsl:value-of select = "@rollno"/></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 = "marks"/></td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
验证输出
xpath_operators.htm
广告