📜  XPath-轴

📅  最后修改于: 2020-11-09 05:39:04             🧑  作者: Mango


由于位置路径使用绝对路径或相对路径定义节点的位置,因此轴用于通过其关系(例如父,子,同级等)来标识元素。之所以命名轴,是因为它们是指相对于元素位于其上的轴元件。

以下是各种Axis值的列表。

S.No. Axis & Description
1

ancestor

Represents the ancestors of the current node which include the parents up to the root node.

2

ancestor-or-self

Represents the current node and it’s ancestors.

3

attribute

Represents the attributes of the current node.

4

child

Represents the children of the current node.

5

descendant

Represents the descendants of the current node. Descendants include the node’s children upto the leaf node(no more children).

6

descendant-or-self

Represents the current node and it’s descendants.

7

following

Represents all nodes that come after the current node.

8

following-sibling

Represents the following siblings of the context node. Siblings are at the same level as the current node and share it’s parent.

9

namespace

Represents the namespace of the current node.

10

parent

Represents the parent of the current node.

11

preceding

Represents all nodes that come before the current node (i.e. before it’s opening tag).

12

self

Represents the current node.

以下是有关轴用途的一些示例。

firstname-选择与学生节点相关的名字。

在此示例中,我们创建了一个示例XML文档students.xml及其样式表文档students.xsl ,该文档使用XPath表达式。

以下是使用的示例XML。

students.xml




   
   
      Dinkar
      Kad
      Dinkar
      85
   
   
      Vaneet
      Gupta
      Vinni
      95
   
   
      Jasvir
      Singh
      Jazz
      90
   

students.xsl


 
    
   

验证输出

XPath轴