I am trying to write an XSLT that organizes an HTML file at different section levels depending on the header level. Here is my input:
<html> <head> <title></title> </head> <body> <h1>HEADER 1 CONTENT</h1> <p>Level 1 para</p> <p>Level 1 para</p> <p>Level 1 para</p> <p>Level 1 para</p> <h2>Header 2 CONTENT</h2> <p>Level 2 para</p> <p>Level 2 para</p> <p>Level 2 para</p> <p>Level 2 para</p> </body> </html>
I am currently working with a fairly simple structure, so this template will be constant for time. I need a conclusion like this ...
<document> <section level="1"> <header1>Header 1 CONTENT</header1> <p>Level 1 para</p> <p>Level 1 para</p> <p>Level 1 para</p> <p>Level 1 para</p> <section level="2"> <header2>Header 2 CONTENT</header2> <p>Level 2 para</p> <p>Level 2 para</p> <p>Level 2 para</p> <p>Level 2 para</p> </section> </section> </document>
I worked with this example: Response to Stokes Stream
However, I cannot get him to do exactly what I need.
I am using Saxon 9 to run xslt in Oxygen for dev. I will use the cmd / bat file in the production process. Still Saxon 9. I would like to process up to 4 levels of nested partitions, if possible.
Any help is much appreciated!
I need to add this as I came across another slander. I probably should have thought of this before.
I meet the following code example
<html> <head> <title></title> </head> <body> <p>Level 1 para</p> <p>Level 1 para</p> <p>Level 1 para</p> <p>Level 1 para</p> <h1>Header 2 CONTENT</h1> <p>Level 2 para</p> <p>Level 2 para</p> <p>Level 2 para</p> <p>Level 2 para</p> </body> </html>
As you can see, <p> is a child of <body> , and in my first snippet, <p> always a child of the header level. My desired result is the same as above, except when I encounter <p> as a child of <body> , it should be wrapped in <section level="1"> .
<document> <section level="1"> <p>Level 1 para</p> <p>Level 1 para</p> <p>Level 1 para</p> <p>Level 1 para</p> </section> <section level="1"> <header1>Header 2 CONTENT</header1> <p>Level 2 para</p> <p>Level 2 para</p> <p>Level 2 para</p> <p>Level 2 para</p> </section> </document>