In our XPath expressions, we've learned that a location path consists of an axis, a node test, and optionally, one or more predicates. We've covered axes and node tests. Now let's look at predicates.
Predicate SyntaxHere's where an XPath goes within our expression (in case you've forgotten!):
axis::node_test[predicate/s]
In the following example, we're using the XSL "value-of" element to select a node. The "select" attribute of this element specifies an XPath expression. In the expression, [@status = 'active'] is the predicate. In this case, the predicate is being used to narrow the selection down to only those records that have their "status" attribute set to "active":
<xsl:value-of select="child::artist[@status = 'active']"/>
An XPath predicate allows you to write very specific rules about the nodes you'd like to select when constructing your expressions. There are different types of expressions that you can use in your predicates. Here are the types of expressions you can use with your predicates:
- Node Set
- Boolean
- Number
- String
- Result tree fragment
Let's have a closer look at these expression types.
No comments:
Post a Comment