The child Axis

The child axis selects from the children of the context node. For example, consider this XPointer:

xpointer(/child::FAMILYTREE/child::PERSON[position()=3]/child::NAME)

Reading from right to left, it selects the NAME child of the third PERSON element that's a child of the FAMILYTREE element that's a child of the root element. In this example, there's only one such element, but if there are more than one then all are returned. For instance consider this XPointer:

xpointer(/child::FAMILYTREE/child::PERSON/child::NAME)

This selects all NAME children of PERSON elements that are children of FAMILYTREE elements that are children of the root. They're a dozen of these in Example 17-1.

It's important to note that the child axis only selects from the immediate children of the context node. For example, consider this URI:

http://www.theharolds.com/genealogy.xml#xpointer(/child::NAME)

This points nowhere because there are no NAME elements in the document that are direct, immediate children of the root node. There are a dozen NAME elements that are indirect children. If you'd like to refer to these, you should use the descendant axis instead of child.

As in XSLT, the child axis is implied if no explicit axis name is present. For instance, the above three XPointers would more likely be written in this abbreviated form:

xpointer(/FAMILYTREE/PERSON[position()=3]/NAME)
xpointer(/FAMILYTREE/PERSON/NAME)
xpointer(/NAME)

Previous | Next | Top | Cafe con Leche

Copyright 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified February 1, 2000