Using the ancestor-or-self Axis

The ancestor-or-self axis contains all the ancestors of the context node, as well as the context node itself. That means, among other things, that this axis always contains the root node.

In the following example, I’ve added an AUTHOR attributes set to “Steve” throughout this document:

Listing 7.4. planets.xml with AUTHOR Attributes
 <?xml version="1.0"?> <?xml-stylesheet type="text/xml" href="planets.xsl"?> <PLANETS AUTHOR="Steve" > <PLANET AUTHOR="Steve"> <NAME>Mercury</NAME> <MASS AUTHOR="Steve" UNITS="(Earth = 1)">.0553</MASS> <DAY UNITS="days">58.65</DAY> <RADIUS UNITS="miles">1516</RADIUS> <DENSITY UNITS="(Earth = 1)">.983</DENSITY> <DISTANCE UNITS="million miles">43.4</DISTANCE><!--At perihelion--> </PLANET> ...

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.