<?python
    num = len(w.children)
?>
<div xmlns:py="http://genshi.edgewall.org/" py:attrs="w.attrs">
    <a href="#" class="subdocuments-add" onclick="return (function(btn) { var el=btn.parentNode.lastChild; while(el.nodeType !== 1) { el = el.previousSibling; } el.style.display = 'block'; return false; })(this)">Add</a>
    <py:for each="i,c in enumerate(w.children)">
        <py:if test="i != (num-1)">
            <a href="#" class="subdocuments-delete" onclick="return (function(btn) { var el=btn.nextSibling; while(el.nodeType !== 1) { el = el.nextSibling; } if (el) { el.remove(); btn.remove(); } return false; })(this)">X</a>
        </py:if>
        ${c.display()}
        <py:if test="w.separator and i != (num-1)">${w.separator}</py:if>
    </py:for>
</div>
