Using the descendant Axis

The descendant axis contains all the descendants of the context node. Note that this does not include any attributes or namespace nodes, because they are not considered child nodes.

The following example puts this axis to work; in this case, I want to add an annotation to Mercury’s <PLANET> element: <INFO>Sorry, Mercury has blown up and is no longer available.</INFO>. To find Mercury, all I have to do is to check whether any descendant of a <PLANET> element has the string value “Mercury”, which I do in an XPath expression inside a match predicate:

Listing 7.6. Using the descendant Axis
 <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml"/> <xsl:template ...

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.