合并XML文档

时间:2013-10-03 21:34:13

标签: xml merge document

我需要根据段落ID合并多个XML文档,如下所述。基本上,它是文档同步情况,其中添加到主文档的paragprahs需要从辅助文档添加;从主文档中删除的段落必须删除辅助文档,最后,主文档段落节点上的某些属性(例如“font”)必须复制到辅助文档,而某些属性需要保留(例如“作者”)。我在c#.net中编写了一些相当粗暴的代码丑陋的代码,它半工作(没有编码属性处理保持/更新逻辑)但更喜欢XSLT解决方案,因为它似乎是XSLT的完美应用程序,但我我是一个XSLT'处女'投入到一个新的“抢购”项目中......有人至少可以让我开始研究如何合并2个文档(即从主人到次要人员添加段落吗?)

例如

master.xml:

<paragraphs>
<paragraph id="intro" font="bold" author="JS">
   <sentences>
         <sentence>Bla bla bla bla</sentence>
         <sentence>More Bla bla bla bla</sentence>
   </sentence> 
</Paragraph>
<paragraph id="main1" font="bold" author="FTG">
   <sentences>
         <sentence>any text here</sentence>
         <sentence>More Bla bla bla bla</sentence>
   </sentence> 
</paragraph>
<paragraph id="main2" font="bold" author="FTG">
   <sentences>
         <sentence>Added to Master Doc</sentence>
   </sentence> 
</Paragraph>

和Secondary.Xml

<paragraphs>
<paragraph id="intro" font="normal" author="ZZ">
   <sentences>
         <sentence>Bla bla bla bla</sentence>
         <sentence>More Bla bla bla bla</sentence>
   </sentence> 
</paragraph>
<paragraph id="main1" font="normal" author="XYZ">
   <sentences>
         <sentence>main1 has been edited in secondary doc but needs to remain unchanged</sentence>
         <sentence>More Bla bla bla bla</sentence>
   </sentence> 
</paragraph>
<paragraph id="conclusion" font="bold" author="FTG">
   <sentences>
         <sentence>In conclusion.....bla.../sentence>
   </sentence> 
</paragraph>
</paragraphs>

需要通过从辅助文档中删除结论段落来合并,将master2 doc从master添加到secondary,将master属性的字体属性应用于匹配的段落,但在匹配的段落中保持author属性不变。后面的部分(属性修复/保留是一个非常小的问题)。

<paragraphs>
<paragraph id="intro" font="bold" author="ZZ">
   <sentences>
         <sentence>Bla bla bla bla</sentence>
         <sentence>More Bla bla bla bla</sentence>
   </sentence> 
</paragraph>
<paragraph id="main1" font="normal" author="FTG">
   <sentences>
         <sentence>main1 has been edited in secondary doc but meeds to remain unchanged</sentence>
         <sentence>More Bla bla bla bla</sentence>
   </sentence> 
</Paragraph>
<paragraph id="main2" font="bold" author="FTG">
   <sentences>
         <sentence>Added to Master Doc</sentence>
   </sentence> 
</Paragraph>
</paragraphs>

0 个答案:

没有答案