import xmlpl.xml; import xmlpl.string; import xmlpl.curl; node[] eval(element e); node[] eval(element e, integer §ion); integer sectionDepth = 1; node[] doSection(element section, string idx); node[] doSubsections(element section, string idx) { if (idx != "") idx = idx + "."; integer count = 1; foreach(section/*) switch(name(.)) { case "section": { doSection(., idx + (string)count++); break; } default: eval(.); } } node[] doSection(element section, string idx) { if (section/@disabled == "true") return; sectionDepth++; string header = "h" + sectionDepth; <(header)> idx; if (idx != "") ") "; value(section/@name); doSubsections(section, idx); sectionDepth --; } node[] doSection(element section) { doSection(section, 1); } node[] doSectionContents(element section) { if (section/@disabled == "true") return;
  • value(section/@name); if (section/section)
      foreach (section/section) doSectionContents(.);
  • } node[] doContents(element e) {

    "Contents";

      foreach (e/../section) doSectionContents(.);
    } node[] doCode(element e) {
    e/node();
    } node[] doInlineCode(element e) { e/node(); } node[] doDefault(element e) { integer section = 1; <(name(e))> e/@*; foreach (e/node()) { if (Element(.)) eval(Element(.), section); else .; } } node[] eval(element e, integer §ion) { switch (name(e)) { case "section": doSection(e, section++); break; case "code": doCode(e); break; case "inline": doInlineCode(e); break; case "contents": doContents(e); break; default: doDefault(e); } } node[] eval(element e) { integer section = 1; eval(e, section); } node[] main(document in) { integer section = 1; foreach (in/*) eval(., section); }