Return to doc.sitecore.com

Valid for Sitecore 6.0.0, 5.3.2
  Axes
Prev Next

The axis component of a query determines the direction of the node selection in relation to the context node. An axis can be thought of as a directional query.

Please follow the link below for more information about Axes in Sitecore:

http://sdn.sitecore.net/Developer/Sitecore%20and%20XSL/Axes.html

 

ancestor Returns all the ancestors of the context Item (same as XPath)
ancestor-or-self Returns the context Item and all the ancestors of the context Item (same as XPath)
child (/*) Returns all the children of the context Item (same as XPath)
descendant (//*) Returns all the descendants of the context Item; a descendant is a child or a child of a child and so on (same as XPath)
descendant-or-self Returns the context Item and all the descendants of the context Item (same as XPath)
following Returns all the following siblings of the context node (same as following-sibling in XPath)
parent (..) Returns the parent Item of the context Item (same as XPath)
preceding Returns all the preceding siblings of the context Item (same as preceding-sibling in XPath)
self (.) returns the context Item (same as XPath)
[int index] Returns the child Item with the mentioned index

 

Examples:

1) query:/sitecore/content/Home/Products/Documents/parent::*/child::*

Result : returns all children of the parent Item of the Documents Item.
  

query:/sitecore/content/Home//*[@@name='Jacket']/ancestor-or-self::*

Result : returns all ancestors of the Jacket Item and the Jacket Item itself.
  

2) query:/sitecore/content/Home/*[@@name='Products']/child::*

Result : returns children of the Products Item.
 

3) query:/sitecore/content/Home/descendant::*[@@name='Documents' or @@name = 'Shapes']

Result : returns Documents and Shapes Items if they are present among the descendants of the Home Item (the functionality of the Axis expression here is the same as that of the //* expression).

 

4) query:/sitecore/content/Home//*[@@name='Stylish Bag' or @@name = 'Shapes']/following::*

Result : returns all Items that follow the Stylish Bag Item and Shapes Item.
 

5) query:self::

Result : returns the Query Test Item, which appears to be the context Item.
 

6) query:/sitecore/content/Home/*[3]

Result : returns the Item under the Home Item whose index is equal to 3.


Prev Next