我有以下 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="3-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="3-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>
<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="5 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>
我需要查看是否在“mainbody”num/@cite 中找到了任何对象/元数据/ref/@cite,然后对象中的 para/text 应该在第一个 Text 节点的末尾复制,并且应该按 object/metadata/ref 排序/@关联。
输出应该是:
<xml>
<mainbody>
<num cite="4.2">4.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**
**applicable on and after December 14, 2007**
</text>
<prov>
<num cite="5 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>