namespace "http://www.w3.org/1999/xhtml";
namespace html = "http://www.w3.org/1999/xhtml";
namespace g="urn:x-mlmind:namespace:group";

for-each //p[matches(., "^\d+\)\s*")] {
    delete-text("^\d+\)\s*");

    set-variable("listItem", <li/>);
    wrap-element($listItem);

    set-attribute("g:id", "numbered", $listItem);
    set-attribute("g:container", "ol", $listItem);
}

for-each //p[preceding-sibling::li[position()=last() and @g:id] and 
             following-sibling::li[position()=1 and @g:id]] {
    set-variable("listItem", preceding-sibling::li[last()]);

    set-attribute("g:id", $listItem/@g:id);
}

group();