Try to select an efficient approach. The use of axes and wildcard characters can radically simplify your code, but that come at the expense of decreased efficiency. For example, the pattern "//*" will match every node in the tree, which is useful if you're trying to search for a given element or attribute but which can be disastrous if your XML structure has 100,000 nodes.
The //* pattern will put all of the nodes in a tree into a single node-set in regular traversal order.
Using universal match for searches is the least efficient way of finding nodes, as it traverses every point in the tree.
The id()
function has been removed from the XSLT specification, but you can search for all elements with given attributes with the XPath expression //*[@id='myID']
.
This pattern can be used to retrieve a list of all direct ancestors of a given node, useful for identifying paths.
Both Axes and Wildcards are perfect for making recursive calls.
This pattern returns ALL sibling nodes after the current node. To get the next node, use:
following::sibling::*[1]