Examples of XPath Expression Results

Table 66 provides examples of XPath expression results:

Expression
Result
              /a
               

            
Returns the document element of the document if it is an a element
              /a/b
               

            
Returns all b elements that are immediate children of the document element, which is the a element
              //a
               

            
Returns all a elements in the document
              //a/b
               

            
Returns all b elements that are immediate children of a elements that are anywhere in the document
              a or ./a
               

            
Returns all a elements that are immediate children of the context node
              a/b
               

            
Returns all b elements that are immediate children of a elements that are immediate children of the context node
              a//b
               

            
Returns all b elements that descend from a elements that are immediate children of the context node
              .//a
               

            
Returns all a elements in the document tree branch that starts with the context node
              ../a
               

            
Returns all a elements in the document tree branch that are children of the parent node of the context node.
Table 66. XPath Expression Results

 
Free Stylus Studio XML Training: