|
XML Home
XML Tutorial About XML XML Viewers XML Editors XML Documents XML Syntax XML Elements XML Attributes XML with CSS XML with XSL XML Namespace XML Local Namespace XML Default Namespace XML Entities XML Creating Entities XML CDATA DTDDTD IntroductionDTD DOCTYPE DTD Internal DTD External DTD Combined DTD FPI DTD Elements DTD Element Operators DTD Attributes DTD Attribute Default Values DTD Attribute Types DTD General Entities DTD Parameter Entities DTD Embedded Images XSLTXSLT IntroductionXSLT Example XSLT Syntax XSLT <template> XSLT <apply-templates> XSLT <value-of> XSLT <for-each> XSLT <sort> XSLT <if> XSLT <choose> XPathXPath IntroductionXPath Location Path XPath Location Path - Absolute XPath Location Path - Relative XPath Attributes XPath Axis XPath Node Test XPath Predicate XPath Node Set XPath Comparison Operators XPath Boolean Operators XPath Number Operators XPath String Functions Tutorial Summary XHTML Tutorial AJAX Tutorial |
XPath AxisYou'll remember from the lesson on location paths that each location path is made up of location steps. Location steps can also include an axis. In this lesson, we'll look at XPath axes (plural for axis). What is an Axis?An axis stores certain information about the context node or other nodes within the document. The information it stores depends on the axis being used. For example, an axis called "child" stores information about the children of the context node. Therefore, we could use this axis to select a child from the context node. SyntaxYou use an axis by using it's name, along with a node test, and optionally, one or more predicates. The axis and node test are separated by Axis without predicates - Here's the syntax you use if you don't have any predicates:
Axis with predicates - Here's the syntax you use if you have one or more predicates:
Axis UsageUp until now, our location steps have specified the exact nodes in the path, or they have used a wildcard to specify unknown nodes. For example, they have been constructed something like this:
We have other options when building our XPath expressions - we could use an axis. Consider the following expression:
This expression looks a little different to the ones we've looked at so far. The expression is selecting a node called "title", but only when it's a child of the context node (remember that context node refers to the current node). You might be thinking, "Yeah that's fine, but how do I know what the context node is?" ExampleHere's an example of how we could use the axis mentioned above:
You'll remember from our XSLT lessons that this statement is selecting the value from a node within the "book" context. We know we're in the "book" context because of the List of AxesThere are many other axes you can use within your XPath expressions. Here's a list of the axes you can use with XPath:
|
Need Website Content?
Get unique, quality digital content for your website.
|