public class XPathLocationStep { String Axis; String NodeTest; Array of Nodes OutputNodeSet; //constructor XPathLocationStep(String XPathLocationStepString) { Resolve the XPathLocationStepString into Axis and NodeTest; }//constructor Array of Nodes getResult(Array of Nodes ContextNodeSet) { OutputNodeSet = new Array of Nodes; Integer NodeCount = Number of nodes in ContextNodeSet; if (Axis is equal to "child" or "descendant") { Repeat NodeCount times for i = 0 to NodeCount-1 { Node node = ContextNodeSet[i]; Integer ChildCount = Number of node's children; Repeat ChildCount times for j = 0 to ChildCount-1 { Node ChildNode = node.getChildElement(j); String ChldName = Name of the ChildNode; if (NodeTest is equal to ChildName) Add ChildNode to OutputNodeSet; if (Axis is equal to "descendant") { Array of Nodes Descendants = getMatchingDescendants(ChildNode); Add MatchingDescendants to OutputNodeSet; }//if (Axis is equal to "descendant") }//Repeat ChildCount times for j = 0 to ChildCount-1 }//Repeat NodeCount times for i = 0 to n-1 }//if (Axis is equal to "child" or "descendant") /* Other Axes */ }//getResult() // This is recursive. private Array of Nodes getMatchingDescendants(Node node) { Array of Nodes MatchingDescendants; Integer ChildCount = Number of node's children; Repeat NodeCount times for j = 0 to ChildCount-1 { Node ChildNode = node.getChildElement(j); String ChildName = Name of the ChildNode; if (NodeTest is equal to ChildName) Add ChildNode to MatchingDescendants; //recursive!! Array of Nodes MoreDescendants = getMatchingDescendants(ChildNode); Add MoreDescendants to MatchingDescendnts; }//Repeat NodeCount times for j = 0 to ChildCount-1 return MatchingDescendants; }//getMatchingDescendants }//class