How to transform 2

L

Luke Olek

Hello! I've posted few days before a message:
How to transform:
<html>
<h1>title</h1>
<h2>header1</h2>
Content
<h3>subeader1</h3>
Subcontent
</html>

to:
<newsletter>
<title>title</title>
<section header="header1">
Content
<subsection header="subheader1">
Subcontent
</subsection>
</section>
</newsletter>

I've received an answer, but I think it isn't what I meant.

Details:
Note, that first file:
<html>
<h1>title</h1>
<h2>header1</h2>
Content
<h3>subeader1</h3>
Subcontent
<h3>subeader2</h3>
Subcontent
<h2>header2</h2>
Content
<h3>subeader3</h3>
Subcontent
<h3>subeader4</h3>
Subcontent
</html>

is a flat file. Every node is on the same level: children of html
node.
What I need is to divide this into deeper structure:

<newsletter>
<title>title</title>
<section header="header1">
Content
<subsection header="subheader1">
Subcontent
</subsection>
<subsection header="subheader2">
Subcontent
</subsection>
</section>
<section header="header1">
Content
<subsection header="subheader1">
Subcontent
</subsection>
<subsection header="subheader2">
Subcontent
</subsection>
</section>
</newsletter>

I don't know is it possible or how to select each node between </h2>
of the current node and <h2> of the next section header.

<html>
<h1>title</h1>
<h2>header1</h2>
---->Content // This becomes the CHILDREN of <section>
created
----><h3>subeader1</h3> // from <h2> above.
---->Subcontent // How to select this as XPath Query?
----><h3>subeader2</h3> // The same will be done with <h3> tags,
but
---->Subcontent // they become <subsection> nodes
<h2>header2</h2>
Content
<h3>subeader3</h3>
Subcontent
<h3>subeader4</h3>
Subcontent
</html>

Any help appreciated!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,814
Latest member
SpicetreeDigital

Latest Threads

Top