public function processNodes(DOMNode $node)
    {
        // get all link nodes
        $allLinkNodes = $this->xp->query('.//a', $node);
        $allLinkNodesSortedByLength = [];
        foreach ($allLinkNodes as $linkNode) {
            $allLinkNodesSortedByLength[] = [
                'href' => $linkNode->getAttribute('href'),
                'node' => $linkNode,
            ];
        }

        // sort by link-length
        usort(
            $allLinkNodesSortedByLength,
            function ($a, $b) {
                $lengthA = strlen($a['href']);
                $lengthB = strlen($b['href']);
                if ($lengthA == $lengthB) {
                    return 0;
                }

                return ($lengthA < $lengthB) ? 1 : -1;
            }
        );

        // set best matching link node to active, all ancestors to open
        $requestedUri = $this->requestedUri;
        while (DIRECTORY_SEPARATOR !== $requestedUri) {
            foreach ($allLinkNodesSortedByLength as $currentLinkNode) {
                if ($currentLinkNode['href'] === $requestedUri) {
                    $currentLinkNode['node']->setAttribute('class', trim($currentLinkNode['node']->getAttribute('class').' '.self::CLASS_ACTIVE));

                    // set nearest li ancestor to active
                    $ancestorListNode = $this->xp->query('./ancestor::li', $currentLinkNode['node'])->item(
                        $this->xp->query('./ancestor::li', $currentLinkNode['node'])->length - 1
                    );
                    $ancestorListNode->setAttribute('class', trim($ancestorListNode->getAttribute('class').' '.self::CLASS_ACTIVE));

                    // set all other li ancestors to open and all links inside them to open
                    $remainingAncestorListNodes = $this->xp->query('ancestor::li', $ancestorListNode);
                    foreach ($remainingAncestorListNodes as $remainingAncestorListNode) {
                        $remainingAncestorListNode->setAttribute('class', trim($remainingAncestorListNode->getAttribute('class').' '.self::CLASS_OPEN));
                        $descendantAnchorNode = $this->xp->query('descendant::a', $remainingAncestorListNode)->item(0);
                        $descendantAnchorNode->setAttribute('class', trim($descendantAnchorNode->getAttribute('class').' '.self::CLASS_OPEN));
                    }

                    return;
                }
            }
            $requestedUri = dirname($requestedUri);
        }

        return false;
    }