|
Resin can use XPath, the XML Path Language, to select nodes from an XML tree. Scripts can select all 'table' children, or even all 'table' elements in an entire HTML file. The XPath language is exceptionally rich. It can describe an incredible number of node selections. Java applications can use the com.caucho.xpath package to use XPath with an XML tree. The XML Path Language describes nodes in an XML tree. It's a mini-language for specifying nodes patterns, like regular expressions are a mini-language for specifying text patterns. The language selects sets of nodes. Each operator in XPath selects a new set based on the old set of nodes. For example, given a set of chapters, XPath can select all sections in those chapters, chapters with 'advanced' attributes, or grandchildren with 'color' attributes of 'blue'.
The basic XPath patterns cover 90% of the cases that most stylesheets will need. Because the pattern language is based on familiar filesystem paths, the most useful patterns should be easy.
Selects all child elements with nodeName of .
Selects all child elements.
Selects the attribute .
Selects all attributes.
Selects elements in the given namespace. Namespace patterns only make sense in the context of XSL, where the namespace declarations have been made.
Matches an org.w3c.dom.Node.
Matches a org.w3c.dom.Text node.
Matches a comment.
Matches a org.w3c.dom.ProcessingInstruction node.
Selects the current node. The current node is primarily useful for descendant patterns. for some filter patterns.
Selects the parent of current node.
Selects the document node. Useful for finding constants in a document.
Select only those nodes matching which also satisfy the expression .The expression is a combination of and, or, not, comparisons and XPath patterns. An XPath expression, e.g. chapter/verse, is true if at least one node matches the pattern.
Selects the th matching node matching When a filter's expression is a number, XPath selects based on position. This special case of the filter pattern treats selections as ordered lists.The position filter is equivalent to [position()= ]
For each node matching , add the nodes matching to the result.The following is almost a definition of a/b.
Some example interpretations,
For each node matching , add the descendant nodes matching to the result. The '//' operator selects all descendants matching . The '/' operator selects all children matching .
Returns elements in the entire document matching .This is equivalent to /.// , but less weird.
All nodes matching or .Some example interpretations,
Uses an expression as the start of a path. Usually, will be a special function call, like the id() function. expr[expr] is also allowed.
The child axis selects children of the current node. It is entirely equivalent to the usual slash notation. So child::a/child::b is the same as a/b.
The descendant axis selects descendants of the current node. It is equivalent to '//'. So child::a//child::b is the same as a//b.
Selects descendants including the current node.
Selects attributes of the current element. It is equivalent to @ .
Selects nodes after the current node.
Selects nodes before the current node. preceding-siblings:: counts positions backwards. So preceding-sibling::a[1] selects the closest preceding sibling.
Selects the first matching node following in document order, excluding descendants. In other words, the following axis will scan through every node in document order, starting with getNextSibling(). following, preceding, ancestor and self partition the document.
Selects the first matching node preceding in document order, excluding ancestors. In other words, the preceding axis will scan through every node in document order, starting with the root and ending in the current node, but it will skip ancestors. following, preceding, ancestor and self partition the document.
Selects the parent if it matches. The '..' pattern from the core is equivalent to 'parent::node()'.
Selects matching ancestors. following, preceding, ancestor and self partition the document.
Selects ancestors including the current node.
Selects the current node. '.' is equivalent to 'self::node()'. following, preceding, ancestor and self partition the document.
Selects nodes based on the .The path interpretation depends on the context. When filtering nodes, the path expression is a boolean. Any matching node will return true. When the value is a string, as in the xsl:value-of, then the textValue is used.
Numbers have the same syntax as Java doubles.
String literals can use single or double quotes.
Standard comparisons. XPath converts the arguments to a common type before comparison. The conversion priority is boolean, number, string. In other words, if either arg is a boolean, a boolean comparison is used.
Node-sets, e.g. chapter/@color, are compared differently. Each node in the node set is compared. If any matches, then the comparison is true.
Arithmetic expressions.
Parenthesized expressions.
Function calls. The function library is in the XPath function section.
Boolean not.
Boolean or.
Boolean and.
The value of a variable. Variables, in general, only make sense in a context like XSL. Normal use of XPath outside of XSL will not use variables.
|