📜  XPath谓词

📅  最后修改于: 2020-12-26 07:06:14             🧑  作者: Mango

XPath谓词

谓词指定用方括号括起来的XPath表达式。在某些情况下,它用于限制节点集中的选定节点。请参见“雇员”示例中的谓词用法。

Employee.xml




   
      Abhiram
      Kushwaha
      Manoj
      15000
   
   
      Akash
      Singh
      Bunty
      25000
   
    
      Brijesh
      Kaushik
      Ballu
      20000
   
    
      Zoya
      Mansoori
      Sonam
      30000
   

Index Predicate Description
1) /class/employee[1] It will select first employee element which is child of the class element.
2) /class/employee[last()] It will select last employee element which is child of the class element.
3) /class/employee[@id = 002] It will select employee element where id is 002.
4) /class/salary[salary > 10000] It will select employee element where salary is greater than 10000.

XPath谓词示例

让我们以一个示例为例,通过遍历每个员工来创建一个元素及其详细信息的表。本示例使用谓词计算雇员节点的位置,然后print雇员详细信息。

Employee.xml




   
      Abhiram
      Kushwaha
      Manoj
      15000
   
   
      Akash
      Singh
      Bunty
      25000
   
    
      Brijesh
      Kaushik
      Ballu
      20000
   
    
      Zoya
      Mansoori
      Sonam
      30000
   

员工.xsl


  
   
      
         
            

Employee

ID First Name Last Name Nick Name Salary

输出:

注意:在上面的示例中,您可以看到所有四个查询均已提取。