// selector for anchor with name attribute only
String nameA = "a[name]:not([href])";
// select all headings that have inner named anchor
List<Element> headingsInnerA = body.select(StringUtil.join(
concat(headNoIds, ":has(" + nameA + ")", true), ", "));
boolean modified = false;
for (Element heading : headingsInnerA) {
List<Element> anchors = heading.select(nameA);