Convert unstructured xml to structured
<p>I've got an unstructured XML which has to be converted to a structured one. 
I am getting this from scientific pdf files parsed by apache tika and converted to xml by Parscit. The xml goes like this:</p>

<p><strong>INPUT</strong>:</p>

<pre><code>&lt;algorithm&gt;
    &lt;sectionHeader&gt; Section1 &lt;/sectionHeader&gt;
    &lt;BodyText&gt;Text goes here&lt;/BodyText&gt;
    &lt;sectionHeader&gt; Section2 &lt;/sectionHeader&gt;
    &lt;BodyText&gt;Text goes here&lt;/BodyText&gt;
    &lt;subsectionHeader&gt;Subsection&lt;/subsectionHeader&gt;
    &lt;BodyText&gt;Text goes here&lt;/BodyText&gt;
    &lt;sectionHeader&gt; Section1 &lt;/sectionHeader&gt;
    &lt;BodyText&gt;Text goes here&lt;/BodyText&gt;
&lt;/algorithm&gt;
</code></pre>

<p><strong>OUTPUT</strong>:</p>

<pre><code>&lt;algorithm&gt;
    &lt;sectionHeader&gt; 
        &lt;Text&gt; Section1 &lt;/Text&gt;
        &lt;BodyText&gt;Text goes here&lt;/BodyText&gt;
    &lt;/sectionHeader&gt;
    &lt;sectionHeader&gt; 
       &lt;Text&gt; Section2 &lt;/Text&gt;
       &lt;BodyText&gt;Text goes here&lt;/BodyText&gt;
    &lt;subsectionHeader&gt;
        &lt;Text&gt;Subsection&lt;/Text&gt;
        &lt;BodyText&gt;Text goes here&lt;/BodyText&gt;
    &lt;/subsectionHeader&gt;
&lt;/sectionHeader&gt;
&lt;sectionHeader&gt; 
    &lt;text&gt;Section3 &lt;/Text&gt;
    &lt;BodyText&gt;Text goes here&lt;/BodyText&gt;
&lt;/sectionHeader&gt;
&lt;/algorithm&gt;
</code></pre>

<p>I am able to do this using string builder and xpath in java. But it affects performance as i may have to process millions of documents. So is <strong>xslt</strong> a better approach?</p>