xml twig algorithm