Using the namespace Axis

The namespace axis contains the namespace nodes of the context node. Note that the axis is empty unless the context node is an element. An element has a namespace node for

  • Every attribute of the element whose name starts with “xmlns:”.

  • Every attribute of an ancestor element whose name starts “xmlns:” (unless, of course, the element itself or a nearer ancestor redeclares the namespace).

  • An xmlns attribute, if the element, or some ancestor, has an xmlns attribute.

In the following example, I’m going to display the namespace of the <PLANETS> element in the result document, and I’m setting that namespace to “http://www.starpowder.com” in the source document:

Listing 7.10. planets.xml with a Namespace Declaration
 <?xml version="1.0"?> ...

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.