I have the following part of an XML (It's ODF)
<office:body>
<office:text text:use-soft-page-breaks="true">
<text:h text:style-name="P1" text:outline-level="1">Heading 1</text:h>
<text:p text:style-name="P2">Paragraph 1</text:p>
<text:h text:style-name="P3" text:outline-level="2">Heading 2</text:h>
<text:p text:style-name="P4">Paragraph 2</text:p>
<text:p text:style-name="P5">Paragraph 3</text:p>
<text:h text:style-name="P6" text:outline-level="3">Heading 3</text:h>
<text:p text:style-name="P7">Paragraph 4</text:p>
<text:p text:style-name="P8">Paragraph 5</text:p>
<text:p text:style-name="P9">Paragraph 6</text:p>
<text:h text:style-name="P10" text:outline-level="4">Heading 4</text:h>
<text:p text:style-name="P11">Paragraph 7</text:p>
<text:h text:style-name="P12" text:outline-level="2">Heading 2</text:h>
<text:p text:style-name="P13">Paragraph 8</text:p>
<text:p text:style-name="P14">Paragraph 9</text:p>
<text:p text:style-name="Normal">
<text:span text:style-name="T15">Paragraph 10</text:span>
</text:p>
</office:text>
</office:body>
I need to transform this to
<Blocks>
<Block>
<Title><![CDATA[Heading 2]]></Title>
<Content>
<![CDATA[<p>Paragraph 2</p><p>Paragraph 3</p><h3>Heading 3</h3><p>Paragraph 4</p><p>Paragraph 5</p><p>Paragraph 6</p><h4>Heading 4</h4><p>Paragraph 7</p>]]>
</Content>
</Block>
<Block>
<Title><![CDATA[Heading 2]]></Title>
<Content>
<![CDATA[<p>Paragraph 8</p><p>Paragraph 9</p><p>Paragraph 10</p>]]>
</Content>
</Block>
</Blocks>
As you can see, I want to create a Block
element for each text:h/@text:outline-level = 2
node.
All following text:p
and text:h/@text:outline-level > 2
siblings should be placed in a Content
element inside the just created Block
element.
How can I achieve that?