📅  最后修改于: 2020-12-26 06:58:13             🧑  作者: Mango
众所周知,路径使用绝对或相对路径定义节点的位置。以相同的方式,XPath轴用于通过其关系(如父,子,同级等)来标识元素。轴是指元素相对于元素所在的轴。
各种Axis值的列表:
Index | Axis | Description |
---|---|---|
1) | ancestor | It specifies the ancestors of the current nodes which include the parents up to the root node. |
2) | ancestor-or-self | It specifies the current node and its ancestors. |
3) | attribute | It specifies the attributes of the current node. |
4) | child | It specifies the children of the current node. |
5) | descendant | It specifies the descendants of the current node i.e. the node’s children up to the leaf node(no more children). |
6) | descendant-or-self | It specifies the current node and it’s descendants. |
7) | following | It specifies all nodes that come after the current node. |
8) | following-sibling | It specifies the following siblings of the context node. Siblings are at the same level as the current node and share it’s parent. |
9) | namespace | It specifies the namespace of the current node. |
10) | parent | It specifies the parent of the current node. |
11) | preceding | It specifies all nodes that come before the current node (i.e. before it’s opening tag). |
12) | self | It specifies the current node. |
这里的名字与XML文档中名为employee.xml的员工节点有关。
让我们创建一个使用XPath表达式的XML文档“ employee.xml”及其样式表文档“ employee.xsl”。
Employee.xml
Abhiram
Kushwaha
Manoj
15000
Akash
Singh
Bunty
25000
Brijesh
Kaushik
Ballu
20000
Zoya
Mansoori
Sonam
30000
员工.xsl
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
First Employee:
输出: