A method generates hierarchical path index keys for single and multiple
indexes with one scan of a document. Each data node of the document is
scanned and matches to query nodes are identified. A data node matches a
query node if the three conditions hold: if it is not the root step,
there is a match for the query node in the previous step of the query;
the data node matches the query node of the current step; and the edges
of the data and query nodes match. A sub-tree of a data node can be
skipped if the data node is not matched and its level is less than the
fixed levels of the query. The matched data node is then placed in the
match stacks corresponding to the match query nodes. The method uses
transitivity properties among matching units to reduce the number of
states that need to be tracked and to improve the evaluation of path
expressions significantly.