Wrong tool
I just spent a lot of time uselessly trying to create an XSLT stylesheet that would number sections in an HTML document based on their header level, and build a nicely nested TOC to boot.
Which doesn’t sound too complicated, but is, because XSLT assumes you’ve used nice sane nested markup, and HTML tends to be insanely nested when nested at all.
So tomorrow I shall chuck it all and do what I should have done in the first place: use SAX, which is the right tool.