Share via


Location Path Examples

A version of this page is also available for

Windows Embedded CE 6.0 R3

4/8/2010

The following examples illustrate the use of location paths.

Select all the children of the context node, whatever their node type.

child::node()

Select the name attribute of the context node.

attribute::name 

Select all the attributes of the context node.

attribute::* 

Select the para element descendants of the context node.

descendant::para 

Select all div ancestors of the context node.

ancestor::div 

Select the div ancestors of the context node and, if the context node is a div element, the context node as well.

ancestor-or-self::div 

Select the para element descendants of the context node and, if the context node is a para element, the context node as well.

descendant-or-self::para 

Select the context node if it is a para element; otherwise select nothing.

self::para 

Select the para element descendants of the chapter element children of the context node.

child::chapter/descendant::para 

Select all para grandchildren of the context node.

child::*/child::para 

Select the document root (which is always the parent of the document element).

/ 

Select all the para elements in the same document as the context node.

/descendant::para

Select all the item elements that have an olist parent and that are in the same document as the context node.

/descendant::olist/child::item 

Select the first para child of the context node.

child::para[position()=1]

Select the last para child of the context node.

child::para[position()=last()] 

Select the next-to-last para child of the context node.

child::para[position()=last()-1] 

Select all the para children of the context node other than the first para child of the context node.

child::para[position()>1]

Select the forty-second figure element in the document.

/descendant::figure[position()=42] 

Select the second section of the fifth chapter of the doc document element.

/child::doc/child::chapter[position()=5]/child::section[position()=2] 

Select all para children of the context node that have a type attribute with value "warning".

child::para[attribute::type="warning"] 

Select the fifth para child of the context node that has a type attribute with value "warning".

child::para[attribute::type="warning"][position()=5] 

Select the fifth para child of the context node if that child has a type attribute with value warning":

child::para[position()=5][attribute::type="warning"] 

Select the chapter children of the context node that have one or more title children with string value equal to "Introduction".

child::chapter[child::title="Introduction"] 

Select the chapter children of the context node that have one or more title children.

child::chapter[child::title] 

Select the chapter and appendix children of the context node.

child::*[self::chapter or self::appendix] 

Select the last chapter or appendix child of the context node.

child::*[self::chapter or self::appendix][position()=last()] 

See Also

Concepts

Location Paths