Location Path Examples

Location Path Examples

Youve seen a lot of location path theory, so how about some examples? The best way to learn this material is by example, so the following list includes a number of location path examples. (The abbreviated versions are next .)

  • child::PLANET . Returns the <PLANET> element children of the context node.

  • child::text() . Returns all text node children of the context node.

  • child::node() . Returns all the children of the context node.

  • attribute::UNIT . Returns the UNIT attribute of the context node.

  • descendant::PLANET . Returns the <PLANET> element descendants of the context node.

  • ancestor ::PLANET . Returns all <PLANET> ancestors of the context node.

  • ancestor-or-self::PLANET . Returns the <PLANET> ancestors of the context node. If the context node is a <PLANET> as well, also returns the context node.

  • descendant-or-self::PLANET . Returns the <PLANET> element descendants of the context node. If the context node is a <PLANET> element as well, also returns the context node.

  • self::PLANET . Returns the context node if the context node is a <PLANET> element.

  • child::PLANET/descendant:: NAME . Returns the <NAME> element descendants of the child <PLANET> elements of the context node.

  • child::*/child::PLANET . Returns all <PLANET> grandchildren of the context node.

  • /. Returns the root node.

  • /descendant::PLANET . Returns all the <PLANET> elements in the document.

  • /descendant::PLANET/child::NAME . Returns all the <NAME> elements that have a <PLANET> parent in the document.

  • child::PLANET[position() = 3] . Returns the third <PLANET> child of the context node.

  • child::PLANET[position() = last()] . Returns the last <PLANET> child of the context node.

  • /descendant::PLANET[position() = 3] . Returns the third <PLANET> element in the document.

  • child::PLANETS/child::PLANET[position() = 4 ]/child::NAME[position() = 3] . Returns the third <NAME> element of the fourth <PLANET> element of the <PLANETS> element.

  • child::PLANET[position() > 3] . Returns all the <PLANET> children of the context node after the first three.

  • preceding -sibling::NAME[position() = 2] . Returns the second previous <NAME> sibling element of the context node.

  • child::*[self::NAME or self::MASS] . Returns both the <NAME> and <MASS> children of the context node.

  • child::*[self::NAME or self::MASS][position() = last()] . Returns the last <NAME> or <MASS> child of the context node.

As you can see, some of this syntax is pretty involved, and a little lengthy to type. However, as with patterns, there is an abbreviated form of XPath syntax.



Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
EAN: N/A
Year: 2005
Pages: 196

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net