1

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

例如

主.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>

需要通过从辅助文档中删除结论段落,将 main2 文档从主文档添加到辅助文档,将主文档的字体属性应用到匹配的段落中,但在匹配的段落上保持作者属性不变。后面部分(属性克隆/保留是一个非常小的问题)。

<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>
4

0 回答 0