Sectioning different heading levels
问题 The goal is to group elements starting with different heading levels into sections nested according to those levels. Problem is similar to XSLT: moving a grouping html elements into section levels. The difference here is that heading levels are not in strict order. To give a simplified example, I want to transform an input like <body> <p>0.1</p> <p>0.2</p> <h2>h2.1</h2> <h3>h3.1</h3> <p>3.1</p> <p>3.2</p> <h1>h1.1</h1> <p>1.1</p> <h3>h3.2</h3> <p>3a.1</p> <p>3a.2</p> </body> into this desired