Skip to main content

XPath Expression

XPath defines a pattern or path expression for selecting nodes or sets of nodes in an XML document.

These patterns are used by XSLT to perform transformations.

XPath Specifications

Nodes

XPath specification specifies seven types of nodes which can be the output of execution of the XPath expression.

XPath specifies seven types of nodes that can be output of the execution of the XPath expression.

  • Root
  • Element
  • Text
  • Attribute
  • Comment
  • Processing Instruction
  • Namespace

Path Selection Expression

XPath uses a path expression to select node or a list of nodes from an XML document.

Following is the list of useful paths and expression to select any node or list of nodes from an XML document.

ExpressionDescription
nodenameIt is used to select all nodes with the given name "nodename"
/It specifies that selection starts from the root node.
//It specifies that selection starts from the current node that match the selection.
.Select the current node.
..Select the parent of the current node.
@Selects attributes.
note

You will discover more in next chapters.