namespace "http://www.w3.org/1999/xhtml";
namespace html = "http://www.w3.org/1999/xhtml";

(: ===========================================================================
   Modify the CSS rules used to number headings
   --------------------------------------------

   1) Delete rules like this one:
---
.n-1-0:after {
    clear: both;
    content: "";
    display: block;
}
---

   2) Modify rules like this one:
---
.n-1-0:before {
    content: counter(n-1-0);
    counter-increment: n-1-0;
    float: left;
    width: 21.6pt;
}
---
   which becomes:
---
.n-1-0:before {
    content: counter(n-1-0) " ";
    counter-increment: n-1-0;
    display: inline;
}
---
=========================================================================== :)

for-each /html/body/p[get-class("^p-Heading\d$")] {
    set-variable("class", get-class("^n-\d+-\d+$"));
    if $class != '' {
        set-variable("selector", concat(".", $class, ":after"));
        if find-rule($selector) >= 0 {
            remove-rule($selector);

            set-variable("selector", concat(".", $class, ":before"));
            set-rule($selector, "float");
            set-rule($selector, "width");
            set-rule($selector, "content",
                     concat(get-rule($selector, "content"), ' " "'));
            set-rule($selector, "display", "inline");
        }
    }
}
