次の構造のxmlがあります
<xml>
<object context="3-cumulative" >
<metadata>
<ref cite="4.2" relevance="first.2"/>
</metadata>
<body>
<para>
<text>
applicable on and after December 14,2007.
</text>
</para>
</body>
</object>
<object context="1-cumulative" >
<metadata>
<ref cite="4.2" relevance="first.1"/>
</metadata>
<body>
<para>
<text>
applicable on and after December 14,2006.
</text>
</para>
</body>
</object>
<object context="1-cumulative" >
<metadata>
<related-content-ref cite="5 annuity" relevance="first.1"/>
</metadata>
<body>
<para>
<text>
applicable on and after December 14, 2008
</text>
</para>
</body>
</object>
<mainbody>
<num cite="4.2">4.2</num>
<num cite="2" type="para">2</num>
<heading>Stock exchanges</heading>
<prov-body>
<text>
Notwithstanding the provisions of a convention ... as defined in the
<italic>Income Tax Act</italic>.
</text>
<prov>
<num cite="1 annuity"/>
<num cite="5 annuity"/>
<num cite="3 annuity"/>
<heading>“annuity”</heading>
<text>
<term>“annuity”</term>does not include any pension payment ...
</text>
<text>
any pension payment ...
</text>
</prov>
</prov-body>
</mainbody>
</xml>
object/metadata/ref/@cite が「mainbody」num/@cite で見つかり、object/@context が「1-cumulative」の場合、オブジェクトの para/text を最初の Text ノードの最後にコピーする必要がありますobject/metadata/ref/@relevance でソートするか、object/metadata/ref/@cite が「mainbody」num/@cite で見つかった場合、object/@context は「3-cumulative」で、para/text from object は、独自の Text 要素を持つ最初の Text ノードの後にコピーし、object/metadata/ref/@relevance でソートする必要があります
出力は次のようになります。
<xml>
<mainbody>
<num cite="4.2">4.2</num>
<num cite="2" type="para">2</num>
<heading>Stock exchanges</heading>
<prov-body>
<text>
Notwithstanding the provisions of a convention ... as defined in the
<italic>Income Tax Act</italic>.
**applicable on and after December 14, 2006**
</text>
<text> **applicable on and after December 14, 2007** </text>
<prov>
<num cite="1 annuity"/>
<num cite="5 annuity"/>
<num cite="3 annuity"/>
<heading>“annuity”</heading>
<text>
<term>“annuity”</term>does not include any pension payment ...
**applicable on and after December 14, 2008**
</text>
<text>
any pension payment ...
</text>
</prov>
</prov-body>
</mainbody>
</xml>