![]() ![]() |
There are several XSL axes, most of which are abbreviated or accessed implicitly in Sitecore. Exception are the ancestor and ancestor-or-self axis, which is often helpful for constructing navigation and inheriting branding elements from the section in which a record resides.
The ancestor-or-self axis returns all elements from the root in document order (see http://www.w3.org/TR/xpath#dt-document-order), which in short is the same order as the opening tags in the XML. For instance, on the node /sitecore/content/home/about, a reference to ancestor-or-self::item first returns /sitecore, then /sitecore/content, then /sitecore/content/home and finally /sitecore/content/home/about.
The descendant and descendant-or-self axes must be considered similarly, though the descendant axes takes special consideration. This axes, generally abbreviated “//”, descends the node tree from the current node and includes all descendants. This operation is expensive and should be avoided; sc:descendants should also be used as an alternative when possible.
Short descriptions of the axes can be found at http://nwalsh.com/docs/tutorials/xsl/xsl/foil22.html. The node identifiers (letters) in this diagram represent the nodes in document order.
Graphic included with permission courtesy of Crane Softwrights Ltd.
In general programmers familiar with other languages begin XSL by creating variables with xsl:variable and calling xsl:for-each to iterate. These constructs are generally avoided in XSL – variables, once defined, cannot be changed, and in general parameters are used instead of variables. The xsl:for-each construct should almost always be avoided in favor of xsl:apply-templates, unless using xsl:apply-templates requires creating a new mode that will be used only once in which case xsl:for-each is preferable.
![](/SdnArchive/images/sdn5/prev.gif)
![](/SdnArchive/images/sdn5/next.gif)