Using the self Axis

The self axis contains just the context node. In fact, one of the XPath abbreviations that you’ll see later is that you can abbreviate “self::node()” as “.”.

This is a useful axis to know about, because as you recall from Chapter 4, if you omit the axis, the default is child::, and sometimes you want to refer to the current node instead. For example, [self::PLANET] is true only if the context node is a <PLANET> element.

In the following example, I combine the templates for <NAME> and <MASS> elements into one template. Because those elements are formatted differently, however, I need to tell them apart inside the same template, and I can do that by checking self::NAME, which returns a non-empty node set if the context node ...

Get Inside XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.